Atherina boyeri

Row

Atherina boyeri

Row

Filtered

Admixed population Pop.1 Pop.2 f3 se Z
Gulf of Lion Costa Calida Algarve -0.18721 0.00032 -593.58131
Gulf of Lion Costa Calida Bay of Biscay 0.43275 0.00066 659.13147
Gulf of Lion Algarve Bay of Biscay -0.17392 0.00039 -440.64356
Costa Calida Gulf of Lion Algarve 3.34744 0.02003 167.12507
Costa Calida Gulf of Lion Bay of Biscay 0.35854 0.00255 140.36586
Costa Calida Algarve Bay of Biscay 0.42055 0.00338 124.35229
Algarve Gulf of Lion Costa Calida 0.39212 0.00053 738.50896
Algarve Gulf of Lion Bay of Biscay 0.37787 0.00058 655.24837
Algarve Costa Calida Bay of Biscay 1.04155 0.00159 656.21067
Bay of Biscay Gulf of Lion Costa Calida 0.15861 0.00153 103.86863
Bay of Biscay Gulf of Lion Algarve 2.26028 0.01282 176.27830
Bay of Biscay Costa Calida Algarve 0.11167 0.00193 57.75881

Unfiltered

Admixed population Pop.1 Pop.2 f3 se Z
Gulf of Lion Costa Calida Algarve -0.14674 0.00056 -262.39827
Gulf of Lion Costa Calida Bay of Biscay 0.36929 0.00082 452.03362
Gulf of Lion Algarve Bay of Biscay -0.13484 0.00063 -215.60341
Costa Calida Gulf of Lion Algarve 2.29495 0.01368 167.78042
Costa Calida Gulf of Lion Bay of Biscay 0.33432 0.00182 183.65553
Costa Calida Algarve Bay of Biscay 0.34689 0.00221 157.08992
Algarve Gulf of Lion Costa Calida 0.44886 0.00092 487.23700
Algarve Gulf of Lion Bay of Biscay 0.43203 0.00093 466.09505
Algarve Costa Calida Bay of Biscay 0.99317 0.00204 485.89131
Bay of Biscay Gulf of Lion Costa Calida 0.21142 0.00152 138.80383
Bay of Biscay Gulf of Lion Algarve 1.66301 0.00874 190.34148
Bay of Biscay Costa Calida Algarve 0.14878 0.00153 97.02609

Alosa fallax

Row

Alosa fallax

Row

Filtered

Admixed population Pop.1 Pop.2 f3 se Z
Gulf of Lion Costa Calida Algarve 0.00000 0.00000 NA
Gulf of Lion Costa Calida Bay of Biscay 0.00000 0.00000 NA
Gulf of Lion Algarve Bay of Biscay 0.50712 0.01124 45.10954
Costa Calida Gulf of Lion Algarve NA NA NA
Costa Calida Gulf of Lion Bay of Biscay NA NA NA
Costa Calida Algarve Bay of Biscay NA NA NA
Algarve Gulf of Lion Costa Calida 0.00000 0.00000 NA
Algarve Gulf of Lion Bay of Biscay 0.03466 0.00186 18.61874
Algarve Costa Calida Bay of Biscay 0.00000 0.00000 NA
Bay of Biscay Gulf of Lion Costa Calida 0.00000 0.00000 NA
Bay of Biscay Gulf of Lion Algarve -0.03050 0.00108 -28.36056
Bay of Biscay Costa Calida Algarve 0.00000 0.00000 NA

Unfiltered

Admixed population Pop.1 Pop.2 f3 se Z
Gulf of Lion Costa Calida Algarve 0.00000 0.00000 NA
Gulf of Lion Costa Calida Bay of Biscay 0.00000 0.00000 NA
Gulf of Lion Algarve Bay of Biscay 0.40692 0.00753 54.02322
Costa Calida Gulf of Lion Algarve NA NA NA
Costa Calida Gulf of Lion Bay of Biscay NA NA NA
Costa Calida Algarve Bay of Biscay NA NA NA
Algarve Gulf of Lion Costa Calida 0.00000 0.00000 NA
Algarve Gulf of Lion Bay of Biscay 0.03268 0.00144 22.61918
Algarve Costa Calida Bay of Biscay 0.00000 0.00000 NA
Bay of Biscay Gulf of Lion Costa Calida 0.00000 0.00000 NA
Bay of Biscay Gulf of Lion Algarve -0.02172 0.00094 -23.12788
Bay of Biscay Costa Calida Algarve 0.00000 0.00000 NA

Coryphoblennius galerita

Row

Coryphoblennius galerita

Row

Filtered

Admixed population Pop.1 Pop.2 f3 se Z
Gulf of Lion Costa Calida Algarve 0.00282 0.00025 11.27338
Gulf of Lion Costa Calida Bay of Biscay 0.00300 0.00025 11.98386
Gulf of Lion Algarve Bay of Biscay 1.60640 0.00992 161.99584
Costa Calida Gulf of Lion Algarve -0.00262 0.00024 -10.72893
Costa Calida Gulf of Lion Bay of Biscay -0.00280 0.00024 -11.47612
Costa Calida Algarve Bay of Biscay 1.59789 0.00994 160.78785
Algarve Gulf of Lion Costa Calida 1.67883 0.00821 204.41064
Algarve Gulf of Lion Bay of Biscay 0.00694 0.00022 31.76221
Algarve Costa Calida Bay of Biscay 0.00712 0.00022 32.56048
Bay of Biscay Gulf of Lion Costa Calida 1.65088 0.00792 208.51369
Bay of Biscay Gulf of Lion Algarve -0.00704 0.00021 -33.74150
Bay of Biscay Costa Calida Algarve -0.00722 0.00021 -34.67910

Unfiltered

Admixed population Pop.1 Pop.2 f3 se Z
Gulf of Lion Costa Calida Algarve 0.00905 0.00042 21.63462
Gulf of Lion Costa Calida Bay of Biscay 0.00899 0.00041 21.89486
Gulf of Lion Algarve Bay of Biscay 1.50874 0.00958 157.55853
Costa Calida Gulf of Lion Algarve 0.00498 0.00049 10.20048
Costa Calida Gulf of Lion Bay of Biscay 0.00429 0.00046 9.29368
Costa Calida Algarve Bay of Biscay 1.52185 0.01000 152.19208
Algarve Gulf of Lion Costa Calida 1.57587 0.00895 176.15860
Algarve Gulf of Lion Bay of Biscay 0.01714 0.00051 33.33483
Algarve Costa Calida Bay of Biscay 0.01771 0.00053 33.23445
Bay of Biscay Gulf of Lion Costa Calida 1.54874 0.00863 179.42131
Bay of Biscay Gulf of Lion Algarve 0.00277 0.00045 6.15025
Bay of Biscay Costa Calida Algarve 0.00273 0.00046 6.00164

Coris julis

Row

Coris julis

Row

Filtered

Admixed population Pop.1 Pop.2 f3 se Z
Gulf of Lion Costa Calida Algarve 0.01034 0.00092 11.24293
Gulf of Lion Costa Calida Bay of Biscay 0.01012 0.00093 10.92210
Gulf of Lion Algarve Bay of Biscay 0.40745 0.00644 63.24034
Costa Calida Gulf of Lion Algarve -0.00643 0.00084 -7.61843
Costa Calida Gulf of Lion Bay of Biscay -0.00622 0.00085 -7.30640
Costa Calida Algarve Bay of Biscay 0.38297 0.00612 62.55411
Algarve Gulf of Lion Costa Calida 0.42342 0.00690 61.39637
Algarve Gulf of Lion Bay of Biscay -0.00417 0.00024 -17.55716
Algarve Costa Calida Bay of Biscay -0.00441 0.00024 -18.63242
Bay of Biscay Gulf of Lion Costa Calida 0.44315 0.00728 60.86077
Bay of Biscay Gulf of Lion Algarve 0.00796 0.00036 22.21123
Bay of Biscay Costa Calida Algarve 0.00820 0.00036 23.01395

Unfiltered

Admixed population Pop.1 Pop.2 f3 se Z
Gulf of Lion Costa Calida Algarve 0.02232 0.00081 27.41548
Gulf of Lion Costa Calida Bay of Biscay 0.02159 0.00081 26.53222
Gulf of Lion Algarve Bay of Biscay 0.39260 0.00496 79.09761
Costa Calida Gulf of Lion Algarve 0.00576 0.00076 7.61204
Costa Calida Gulf of Lion Bay of Biscay 0.00596 0.00076 7.83289
Costa Calida Algarve Bay of Biscay 0.36949 0.00470 78.55810
Algarve Gulf of Lion Costa Calida 0.41944 0.00547 76.61235
Algarve Gulf of Lion Bay of Biscay 0.00979 0.00037 26.79076
Algarve Costa Calida Bay of Biscay 0.00946 0.00036 26.10079
Bay of Biscay Gulf of Lion Costa Calida 0.44318 0.00584 75.94638
Bay of Biscay Gulf of Lion Algarve 0.02566 0.00051 49.97274
Bay of Biscay Costa Calida Algarve 0.02611 0.00052 50.43606

Dicentrarchus labrax

Row

Dicentrarchus labrax

Row

Filtered

Admixed population Pop.1 Pop.2 f3 se Z
Gulf of Lion Costa Calida Algarve -0.00254 0.00098 -2.59870
Gulf of Lion Costa Calida Bay of Biscay -0.00457 0.00130 -3.51914
Gulf of Lion Algarve Bay of Biscay 0.14086 0.00667 21.13138
Costa Calida Gulf of Lion Algarve 0.00934 0.00118 7.91411
Costa Calida Gulf of Lion Bay of Biscay 0.01141 0.00151 7.55970
Costa Calida Algarve Bay of Biscay 0.15799 0.00707 22.34062
Algarve Gulf of Lion Costa Calida 0.09206 0.00424 21.71770
Algarve Gulf of Lion Bay of Biscay -0.03446 0.00164 -21.07085
Algarve Costa Calida Bay of Biscay -0.03625 0.00171 -21.19940
Bay of Biscay Gulf of Lion Costa Calida 0.18428 0.00843 21.85150
Bay of Biscay Gulf of Lion Algarve 0.04926 0.00283 17.41844
Bay of Biscay Costa Calida Algarve 0.05114 0.00293 17.44106

Unfiltered

Admixed population Pop.1 Pop.2 f3 se Z
Gulf of Lion Costa Calida Algarve -0.00037 0.00085 -0.43140
Gulf of Lion Costa Calida Bay of Biscay -0.00232 0.00111 -2.08529
Gulf of Lion Algarve Bay of Biscay 0.12697 0.00559 22.70460
Costa Calida Gulf of Lion Algarve 0.01078 0.00097 11.14093
Costa Calida Gulf of Lion Bay of Biscay 0.01276 0.00125 10.22836
Costa Calida Algarve Bay of Biscay 0.14227 0.00591 24.07083
Algarve Gulf of Lion Costa Calida 0.08320 0.00361 23.05902
Algarve Gulf of Lion Bay of Biscay -0.02930 0.00142 -20.63007
Algarve Costa Calida Bay of Biscay -0.03110 0.00149 -20.91128
Bay of Biscay Gulf of Lion Costa Calida 0.16426 0.00705 23.29831
Bay of Biscay Gulf of Lion Algarve 0.04525 0.00237 19.08543
Bay of Biscay Costa Calida Algarve 0.04703 0.00246 19.10234

Diplodus puntazzo

Row

Diplodus puntazzo

Row

Filtered

Admixed population Pop.1 Pop.2 f3 se Z
Gulf of Lion Costa Calida Algarve 0.10558 0.00181 58.30701
Gulf of Lion Costa Calida Bay of Biscay 0.10792 0.00187 57.68456
Gulf of Lion Algarve Bay of Biscay 1.71666 0.02209 77.70301
Costa Calida Gulf of Lion Algarve -0.08244 0.00118 -69.94966
Costa Calida Gulf of Lion Bay of Biscay -0.08433 0.00122 -69.04709
Costa Calida Algarve Bay of Biscay 1.22222 0.01391 87.86862
Algarve Gulf of Lion Costa Calida 1.42471 0.01618 88.06859
Algarve Gulf of Lion Bay of Biscay -0.02580 0.00150 -17.21716
Algarve Costa Calida Bay of Biscay -0.02370 0.00141 -16.80209
Bay of Biscay Gulf of Lion Costa Calida 1.62476 0.01963 82.74978
Bay of Biscay Gulf of Lion Algarve 0.04879 0.00167 29.21740
Bay of Biscay Costa Calida Algarve 0.04650 0.00156 29.72434

Unfiltered

Admixed population Pop.1 Pop.2 f3 se Z
Gulf of Lion Costa Calida Algarve 0.09905 0.00139 71.29504
Gulf of Lion Costa Calida Bay of Biscay 0.10064 0.00144 70.05473
Gulf of Lion Algarve Bay of Biscay 1.43620 0.01735 82.78929
Costa Calida Gulf of Lion Algarve -0.05870 0.00123 -47.69983
Costa Calida Gulf of Lion Bay of Biscay -0.06002 0.00127 -47.20637
Costa Calida Algarve Bay of Biscay 1.07461 0.01155 93.02598
Algarve Gulf of Lion Costa Calida 1.20523 0.01302 92.60142
Algarve Gulf of Lion Bay of Biscay -0.00885 0.00140 -6.32057
Algarve Costa Calida Bay of Biscay -0.00741 0.00133 -5.57510
Bay of Biscay Gulf of Lion Costa Calida 1.35342 0.01543 87.71588
Bay of Biscay Gulf of Lion Algarve 0.05945 0.00146 40.71393
Bay of Biscay Costa Calida Algarve 0.05786 0.00139 41.54807

Gobius niger

Row

Gobius niger

Row

Filtered

Admixed population Pop.1 Pop.2 f3 se Z
Gulf of Lion Costa Calida Algarve 0.04579 0.00045 101.93166
Gulf of Lion Costa Calida Bay of Biscay 0.04909 0.00041 118.59769
Gulf of Lion Algarve Bay of Biscay 0.10766 0.00070 152.93672
Costa Calida Gulf of Lion Algarve 0.04692 0.00046 102.52304
Costa Calida Gulf of Lion Bay of Biscay 0.04351 0.00045 96.16733
Costa Calida Algarve Bay of Biscay 0.10849 0.00080 135.18049
Algarve Gulf of Lion Costa Calida 0.13178 0.00106 124.34025
Algarve Gulf of Lion Bay of Biscay 0.06477 0.00069 93.53926
Algarve Costa Calida Bay of Biscay 0.06832 0.00070 97.20569
Bay of Biscay Gulf of Lion Costa Calida 0.09672 0.00041 237.84656
Bay of Biscay Gulf of Lion Algarve 0.03248 0.00037 86.87264
Bay of Biscay Costa Calida Algarve 0.02891 0.00038 76.05266

Unfiltered

Admixed population Pop.1 Pop.2 f3 se Z
Gulf of Lion Costa Calida Algarve 0.05474 0.00037 149.29913
Gulf of Lion Costa Calida Bay of Biscay 0.05773 0.00035 163.54806
Gulf of Lion Algarve Bay of Biscay 0.10890 0.00051 212.40296
Costa Calida Gulf of Lion Algarve 0.05198 0.00037 140.13785
Costa Calida Gulf of Lion Bay of Biscay 0.04818 0.00036 135.15262
Costa Calida Algarve Bay of Biscay 0.10734 0.00059 182.00714
Algarve Gulf of Lion Costa Calida 0.13086 0.00079 166.60309
Algarve Gulf of Lion Bay of Biscay 0.06696 0.00051 130.20678
Algarve Costa Calida Bay of Biscay 0.07162 0.00053 134.25322
Bay of Biscay Gulf of Lion Costa Calida 0.11360 0.00057 198.46065
Bay of Biscay Gulf of Lion Algarve 0.05135 0.00054 94.72488
Bay of Biscay Costa Calida Algarve 0.04891 0.00056 87.51130

Hippocampus guttulatus

Row

Hippocampus guttulatus

Row

Filtered

Admixed population Pop.1 Pop.2 f3 se Z
Gulf of Lion Costa Calida Algarve 0.03409 0.00685 4.97589
Gulf of Lion Costa Calida Bay of Biscay 0.02769 0.00666 4.15719
Gulf of Lion Algarve Bay of Biscay 0.09988 0.00532 18.77763
Costa Calida Gulf of Lion Algarve 0.04493 0.00852 5.27421
Costa Calida Gulf of Lion Bay of Biscay 0.05111 0.00869 5.88141
Costa Calida Algarve Bay of Biscay 0.11433 0.01610 7.10327
Algarve Gulf of Lion Costa Calida 0.29649 0.01522 19.47888
Algarve Gulf of Lion Bay of Biscay 0.20459 0.00596 34.33047
Algarve Costa Calida Bay of Biscay 0.19564 0.00532 36.80177
Bay of Biscay Gulf of Lion Costa Calida 0.22148 0.01772 12.49815
Bay of Biscay Gulf of Lion Algarve 0.14858 0.01687 8.80730
Bay of Biscay Costa Calida Algarve 0.15510 0.01685 9.20574

Unfiltered

Admixed population Pop.1 Pop.2 f3 se Z
Gulf of Lion Costa Calida Algarve 0.03264 0.00622 5.25234
Gulf of Lion Costa Calida Bay of Biscay 0.02694 0.00608 4.42733
Gulf of Lion Algarve Bay of Biscay 0.09468 0.00482 19.66256
Costa Calida Gulf of Lion Algarve 0.04208 0.00781 5.38605
Costa Calida Gulf of Lion Bay of Biscay 0.04778 0.00799 5.97821
Costa Calida Algarve Bay of Biscay 0.10752 0.01481 7.26130
Algarve Gulf of Lion Costa Calida 0.27576 0.01403 19.65029
Algarve Gulf of Lion Bay of Biscay 0.19031 0.00554 34.35477
Algarve Costa Calida Bay of Biscay 0.18263 0.00498 36.64585
Bay of Biscay Gulf of Lion Costa Calida 0.20854 0.01638 12.73415
Bay of Biscay Gulf of Lion Algarve 0.13991 0.01543 9.06596
Bay of Biscay Costa Calida Algarve 0.14604 0.01542 9.46808

Lophius budegassa

Row

Lophius budegassa

Row

Filtered

Admixed population Pop.1 Pop.2 f3 se Z
Gulf of Lion Costa Calida Algarve 0.00048 0.00026 1.86626
Gulf of Lion Costa Calida Bay of Biscay 0.00073 0.00029 2.50044
Gulf of Lion Algarve Bay of Biscay 0.00228 0.00025 8.98570
Costa Calida Gulf of Lion Algarve -0.00040 0.00033 -1.19235
Costa Calida Gulf of Lion Bay of Biscay -0.00065 0.00034 -1.89835
Costa Calida Algarve Bay of Biscay 0.00115 0.00032 3.56600
Algarve Gulf of Lion Costa Calida 0.00098 0.00022 4.50221
Algarve Gulf of Lion Bay of Biscay -0.00081 0.00021 -3.78432
Algarve Costa Calida Bay of Biscay -0.00056 0.00022 -2.57613
Bay of Biscay Gulf of Lion Costa Calida 0.00358 0.00027 13.02912
Bay of Biscay Gulf of Lion Algarve 0.00207 0.00023 8.85039
Bay of Biscay Costa Calida Algarve 0.00183 0.00024 7.61973

Unfiltered

Admixed population Pop.1 Pop.2 f3 se Z
Gulf of Lion Costa Calida Algarve 0.00051 0.00036 1.39119
Gulf of Lion Costa Calida Bay of Biscay 0.00065 0.00037 1.76009
Gulf of Lion Algarve Bay of Biscay 0.00213 0.00037 5.76564
Costa Calida Gulf of Lion Algarve -0.00050 0.00053 -0.93687
Costa Calida Gulf of Lion Bay of Biscay -0.00072 0.00054 -1.33871
Costa Calida Algarve Bay of Biscay 0.00086 0.00054 1.57753
Algarve Gulf of Lion Costa Calida 0.00103 0.00034 3.03920
Algarve Gulf of Lion Bay of Biscay -0.00037 0.00035 -1.06072
Algarve Costa Calida Bay of Biscay -0.00032 0.00033 -0.97393
Bay of Biscay Gulf of Lion Costa Calida 0.00357 0.00036 9.85468
Bay of Biscay Gulf of Lion Algarve 0.00238 0.00037 6.46156
Bay of Biscay Costa Calida Algarve 0.00211 0.00035 6.01625

Lithognathus mormyrus

Row

Lithognathus mormyrus

Row

Filtered

Admixed population Pop.1 Pop.2 f3 se Z
Gulf of Lion Costa Calida Algarve 0.01779 0.00065 27.41184
Gulf of Lion Costa Calida Bay of Biscay 0.01797 0.00066 27.14765
Gulf of Lion Algarve Bay of Biscay 1.93847 0.02710 71.53010
Costa Calida Gulf of Lion Algarve -0.01252 0.00060 -20.93382
Costa Calida Gulf of Lion Bay of Biscay -0.01270 0.00060 -21.01126
Costa Calida Algarve Bay of Biscay 1.85769 0.02592 71.65769
Algarve Gulf of Lion Costa Calida 1.68535 0.01662 101.41699
Algarve Gulf of Lion Bay of Biscay 0.00294 0.00157 1.86972
Algarve Costa Calida Bay of Biscay 0.00309 0.00157 1.97262
Bay of Biscay Gulf of Lion Costa Calida 1.94008 0.01938 100.10343
Bay of Biscay Gulf of Lion Algarve 0.06801 0.00165 41.19180
Bay of Biscay Costa Calida Algarve 0.06785 0.00164 41.30805

Unfiltered

Admixed population Pop.1 Pop.2 f3 se Z
Gulf of Lion Costa Calida Algarve 0.02358 0.00068 34.57216
Gulf of Lion Costa Calida Bay of Biscay 0.02387 0.00070 34.25980
Gulf of Lion Algarve Bay of Biscay 1.73229 0.02248 77.05435
Costa Calida Gulf of Lion Algarve -0.00494 0.00065 -7.64453
Costa Calida Gulf of Lion Bay of Biscay -0.00547 0.00064 -8.57047
Costa Calida Algarve Bay of Biscay 1.66159 0.02154 77.13381
Algarve Gulf of Lion Costa Calida 1.50657 0.01376 109.45893
Algarve Gulf of Lion Bay of Biscay 0.01050 0.00143 7.33721
Algarve Costa Calida Bay of Biscay 0.01075 0.00143 7.53144
Bay of Biscay Gulf of Lion Costa Calida 1.74564 0.01598 109.24403
Bay of Biscay Gulf of Lion Algarve 0.07643 0.00157 48.82478
Bay of Biscay Costa Calida Algarve 0.07604 0.00155 48.93170

Merluccius merluccius

Row

Merluccius merluccius

Row

Filtered

Admixed population Pop.1 Pop.2 f3 se Z
Gulf of Lion Costa Calida Algarve 0.00642 0.00035 18.13031
Gulf of Lion Costa Calida Bay of Biscay 0.00692 0.00037 18.64751
Gulf of Lion Algarve Bay of Biscay 0.03590 0.00093 38.46309
Costa Calida Gulf of Lion Algarve -0.00338 0.00029 -11.53857
Costa Calida Gulf of Lion Bay of Biscay -0.00388 0.00031 -12.60526
Costa Calida Algarve Bay of Biscay 0.02540 0.00074 34.48674
Algarve Gulf of Lion Costa Calida 0.02442 0.00072 33.78390
Algarve Gulf of Lion Bay of Biscay -0.00497 0.00034 -14.83124
Algarve Costa Calida Bay of Biscay -0.00447 0.00032 -13.99727
Bay of Biscay Gulf of Lion Costa Calida 0.03749 0.00095 39.59215
Bay of Biscay Gulf of Lion Algarve 0.00829 0.00037 22.34891
Bay of Biscay Costa Calida Algarve 0.00779 0.00034 22.57730

Unfiltered

Admixed population Pop.1 Pop.2 f3 se Z
Gulf of Lion Costa Calida Algarve 0.01518 0.00072 20.99681
Gulf of Lion Costa Calida Bay of Biscay 0.01556 0.00074 21.14635
Gulf of Lion Algarve Bay of Biscay 0.04040 0.00093 43.38858
Costa Calida Gulf of Lion Algarve 0.00510 0.00060 8.42874
Costa Calida Gulf of Lion Bay of Biscay 0.00469 0.00061 7.72372
Costa Calida Algarve Bay of Biscay 0.03014 0.00076 39.72446
Algarve Gulf of Lion Costa Calida 0.02944 0.00077 38.14641
Algarve Gulf of Lion Bay of Biscay 0.00395 0.00063 6.23000
Algarve Costa Calida Bay of Biscay 0.00454 0.00064 7.06885
Bay of Biscay Gulf of Lion Costa Calida 0.04072 0.00089 45.86423
Bay of Biscay Gulf of Lion Algarve 0.01552 0.00066 23.53188
Bay of Biscay Costa Calida Algarve 0.01533 0.00065 23.41329

Mullus surmuletus

Row

Mullus surmuletus

Row

Filtered

Admixed population Pop.1 Pop.2 f3 se Z
Gulf of Lion Costa Calida Algarve 0.02557 0.00149 17.10891
Gulf of Lion Costa Calida Bay of Biscay 0.02277 0.00140 16.24458
Gulf of Lion Algarve Bay of Biscay 0.05909 0.00329 17.98740
Costa Calida Gulf of Lion Algarve -0.01474 0.00091 -16.17138
Costa Calida Gulf of Lion Bay of Biscay -0.01200 0.00087 -13.77794
Costa Calida Algarve Bay of Biscay 0.02087 0.00130 16.08676
Algarve Gulf of Lion Costa Calida 0.04067 0.00219 18.54007
Algarve Gulf of Lion Bay of Biscay 0.00684 0.00097 7.01952
Algarve Costa Calida Bay of Biscay 0.00402 0.00062 6.45925
Bay of Biscay Gulf of Lion Costa Calida 0.03581 0.00223 16.02718
Bay of Biscay Gulf of Lion Algarve -0.00074 0.00081 -0.91592
Bay of Biscay Costa Calida Algarve 0.00208 0.00056 3.68789

Unfiltered

Admixed population Pop.1 Pop.2 f3 se Z
Gulf of Lion Costa Calida Algarve 0.02836 0.00133 21.24671
Gulf of Lion Costa Calida Bay of Biscay 0.02570 0.00126 20.46506
Gulf of Lion Algarve Bay of Biscay 0.06029 0.00285 21.12679
Costa Calida Gulf of Lion Algarve -0.00951 0.00087 -10.93200
Costa Calida Gulf of Lion Bay of Biscay -0.00684 0.00083 -8.19952
Costa Calida Algarve Bay of Biscay 0.02498 0.00120 20.82326
Algarve Gulf of Lion Costa Calida 0.04411 0.00197 22.44080
Algarve Gulf of Lion Bay of Biscay 0.01100 0.00094 11.64167
Algarve Costa Calida Bay of Biscay 0.00859 0.00066 12.93590
Bay of Biscay Gulf of Lion Costa Calida 0.03900 0.00199 19.56617
Bay of Biscay Gulf of Lion Algarve 0.00322 0.00079 4.08758
Bay of Biscay Costa Calida Algarve 0.00619 0.00060 10.30860

Pagellus erythrinus

Row

Pagellus erythrinus

Row

Filtered

Admixed population Pop.1 Pop.2 f3 se Z
Gulf of Lion Costa Calida Algarve 0.00194 0.00013 14.85178
Gulf of Lion Costa Calida Bay of Biscay 0.00127 0.00014 8.80373
Gulf of Lion Algarve Bay of Biscay 0.00198 0.00016 12.57288
Costa Calida Gulf of Lion Algarve 0.00111 0.00013 8.75568
Costa Calida Gulf of Lion Bay of Biscay 0.00178 0.00014 12.79166
Costa Calida Algarve Bay of Biscay 0.00183 0.00014 13.12720
Algarve Gulf of Lion Costa Calida 0.00290 0.00013 22.76788
Algarve Gulf of Lion Bay of Biscay 0.00287 0.00015 19.79395
Algarve Costa Calida Bay of Biscay 0.00235 0.00012 19.51904
Bay of Biscay Gulf of Lion Costa Calida 0.00751 0.00047 16.06981
Bay of Biscay Gulf of Lion Algarve 0.00680 0.00045 15.16267
Bay of Biscay Costa Calida Algarve 0.00747 0.00050 14.87093

Unfiltered

Admixed population Pop.1 Pop.2 f3 se Z
Gulf of Lion Costa Calida Algarve 0.01087 0.00035 31.34060
Gulf of Lion Costa Calida Bay of Biscay 0.01012 0.00035 28.85658
Gulf of Lion Algarve Bay of Biscay 0.01117 0.00037 30.36853
Costa Calida Gulf of Lion Algarve 0.01016 0.00035 28.67041
Costa Calida Gulf of Lion Bay of Biscay 0.01069 0.00036 29.74098
Costa Calida Algarve Bay of Biscay 0.01109 0.00036 30.54775
Algarve Gulf of Lion Costa Calida 0.01138 0.00034 33.90707
Algarve Gulf of Lion Bay of Biscay 0.01128 0.00034 33.24330
Algarve Costa Calida Bay of Biscay 0.01070 0.00033 32.78164
Bay of Biscay Gulf of Lion Costa Calida 0.01586 0.00051 31.36122
Bay of Biscay Gulf of Lion Algarve 0.01515 0.00049 30.80533
Bay of Biscay Costa Calida Algarve 0.01576 0.00053 29.75453

Serranus cabrilla

Row

Serranus cabrilla

Row

Filtered

Admixed population Pop.1 Pop.2 f3 se Z
Gulf of Lion Costa Calida Algarve 0.06642 0.00290 22.88850
Gulf of Lion Costa Calida Bay of Biscay 0.06579 0.00290 22.65320
Gulf of Lion Algarve Bay of Biscay 0.15705 0.00594 26.43114
Costa Calida Gulf of Lion Algarve -0.03728 0.00141 -26.44629
Costa Calida Gulf of Lion Bay of Biscay -0.03670 0.00140 -26.12553
Costa Calida Algarve Bay of Biscay 0.04639 0.00173 26.77482
Algarve Gulf of Lion Costa Calida 0.09672 0.00362 26.72383
Algarve Gulf of Lion Bay of Biscay 0.00581 0.00098 5.93858
Algarve Costa Calida Bay of Biscay 0.00517 0.00064 8.07494
Bay of Biscay Gulf of Lion Costa Calida 0.09266 0.00342 27.13082
Bay of Biscay Gulf of Lion Algarve 0.00392 0.00090 4.36154
Bay of Biscay Costa Calida Algarve 0.00454 0.00055 8.18975

Unfiltered

Admixed population Pop.1 Pop.2 f3 se Z
Gulf of Lion Costa Calida Algarve 0.06435 0.00263 24.49459
Gulf of Lion Costa Calida Bay of Biscay 0.06372 0.00263 24.21249
Gulf of Lion Algarve Bay of Biscay 0.14911 0.00539 27.65027
Costa Calida Gulf of Lion Algarve -0.03241 0.00133 -24.42239
Costa Calida Gulf of Lion Bay of Biscay -0.03184 0.00132 -24.04496
Costa Calida Algarve Bay of Biscay 0.04591 0.00158 28.99262
Algarve Gulf of Lion Costa Calida 0.09342 0.00327 28.53088
Algarve Gulf of Lion Bay of Biscay 0.00846 0.00092 9.15279
Algarve Costa Calida Bay of Biscay 0.00765 0.00062 12.34947
Bay of Biscay Gulf of Lion Costa Calida 0.08965 0.00305 29.40322
Bay of Biscay Gulf of Lion Algarve 0.00758 0.00085 8.92185
Bay of Biscay Costa Calida Algarve 0.00800 0.00055 14.59290

Spondyliosoma cantharus

Row

Spondyliosoma cantharus

Row

Filtered

Admixed population Pop.1 Pop.2 f3 se Z
Gulf of Lion Costa Calida Algarve 0.01368 0.00122 11.23659
Gulf of Lion Costa Calida Bay of Biscay 0.01345 0.00121 11.14824
Gulf of Lion Algarve Bay of Biscay 0.87437 0.01797 48.64379
Costa Calida Gulf of Lion Algarve -0.01366 0.00115 -11.83209
Costa Calida Gulf of Lion Bay of Biscay -0.01343 0.00114 -11.74135
Costa Calida Algarve Bay of Biscay 0.81984 0.01647 49.77321
Algarve Gulf of Lion Costa Calida 0.72315 0.01177 61.42277
Algarve Gulf of Lion Bay of Biscay 0.00190 0.00065 2.92296
Algarve Costa Calida Bay of Biscay 0.00171 0.00065 2.61447
Bay of Biscay Gulf of Lion Costa Calida 0.74199 0.01211 61.28416
Bay of Biscay Gulf of Lion Algarve 0.00925 0.00069 13.32699
Bay of Biscay Costa Calida Algarve 0.00945 0.00070 13.46708

Unfiltered

Admixed population Pop.1 Pop.2 f3 se Z
Gulf of Lion Costa Calida Algarve 0.01473 0.00104 14.17925
Gulf of Lion Costa Calida Bay of Biscay 0.01450 0.00103 14.07915
Gulf of Lion Algarve Bay of Biscay 0.78754 0.01476 53.36036
Costa Calida Gulf of Lion Algarve -0.00822 0.00102 -8.09431
Costa Calida Gulf of Lion Bay of Biscay -0.00809 0.00100 -8.05361
Costa Calida Algarve Bay of Biscay 0.73881 0.01354 54.57059
Algarve Gulf of Lion Costa Calida 0.65323 0.00955 68.41537
Algarve Gulf of Lion Bay of Biscay 0.00615 0.00065 9.51368
Algarve Costa Calida Bay of Biscay 0.00584 0.00065 9.03061
Bay of Biscay Gulf of Lion Costa Calida 0.67015 0.00979 68.42163
Bay of Biscay Gulf of Lion Algarve 0.01297 0.00067 19.23346
Bay of Biscay Costa Calida Algarve 0.01291 0.00067 19.16273

Symphodus cinereus

Row

Symphodus cinereus

Row

Filtered

Admixed population Pop.1 Pop.2 f3 se Z
Gulf of Lion Costa Calida Algarve 0.07123 0.00129 55.24219
Gulf of Lion Costa Calida Bay of Biscay 0.06766 0.00125 53.97680
Gulf of Lion Algarve Bay of Biscay 0.08839 0.00153 57.91320
Costa Calida Gulf of Lion Algarve 0.00967 0.00052 18.70656
Costa Calida Gulf of Lion Bay of Biscay 0.01284 0.00064 19.96263
Costa Calida Algarve Bay of Biscay 0.02881 0.00084 34.11700
Algarve Gulf of Lion Costa Calida 0.05438 0.00106 51.26113
Algarve Gulf of Lion Bay of Biscay 0.03709 0.00098 37.92549
Algarve Costa Calida Bay of Biscay 0.03367 0.00085 39.66983
Bay of Biscay Gulf of Lion Costa Calida 0.41546 0.00380 109.35563
Bay of Biscay Gulf of Lion Algarve 0.38178 0.00349 109.50224
Bay of Biscay Costa Calida Algarve 0.38742 0.00353 109.73229

Unfiltered

Admixed population Pop.1 Pop.2 f3 se Z
Gulf of Lion Costa Calida Algarve 0.07214 0.00114 63.04580
Gulf of Lion Costa Calida Bay of Biscay 0.06744 0.00109 61.81649
Gulf of Lion Algarve Bay of Biscay 0.08627 0.00131 65.91299
Costa Calida Gulf of Lion Algarve 0.01514 0.00061 24.95570
Costa Calida Gulf of Lion Bay of Biscay 0.01712 0.00065 26.15452
Costa Calida Algarve Bay of Biscay 0.03219 0.00081 39.58725
Algarve Gulf of Lion Costa Calida 0.05761 0.00100 57.50396
Algarve Gulf of Lion Bay of Biscay 0.03930 0.00088 44.59501
Algarve Costa Calida Bay of Biscay 0.03649 0.00079 46.14391
Bay of Biscay Gulf of Lion Costa Calida 0.39577 0.00356 111.11324
Bay of Biscay Gulf of Lion Algarve 0.36350 0.00326 111.64960
Bay of Biscay Costa Calida Algarve 0.36983 0.00333 110.95982

Sardina pilchardus

Row

Sardina pilchardus

Row

Filtered

Admixed population Pop.1 Pop.2 f3 se Z
Gulf of Lion Costa Calida Algarve 0.00513 0.00044 11.65146
Gulf of Lion Costa Calida Bay of Biscay 0.00255 0.00038 6.63812
Gulf of Lion Algarve Bay of Biscay 0.01775 0.00079 22.53672
Costa Calida Gulf of Lion Algarve -0.00094 0.00040 -2.31180
Costa Calida Gulf of Lion Bay of Biscay 0.00162 0.00035 4.62006
Costa Calida Algarve Bay of Biscay 0.01412 0.00057 24.82860
Algarve Gulf of Lion Costa Calida 0.02233 0.00104 21.52388
Algarve Gulf of Lion Bay of Biscay 0.01008 0.00074 13.64796
Algarve Costa Calida Bay of Biscay 0.00757 0.00066 11.47039
Bay of Biscay Gulf of Lion Costa Calida 0.01561 0.00066 23.79155
Bay of Biscay Gulf of Lion Algarve 0.00055 0.00057 0.96575
Bay of Biscay Costa Calida Algarve 0.00311 0.00050 6.27167

Unfiltered

Admixed population Pop.1 Pop.2 f3 se Z
Gulf of Lion Costa Calida Algarve 0.03203 0.00059 54.49861
Gulf of Lion Costa Calida Bay of Biscay 0.03021 0.00059 51.54053
Gulf of Lion Algarve Bay of Biscay 0.04409 0.00073 60.49556
Costa Calida Gulf of Lion Algarve 0.02568 0.00057 45.34397
Costa Calida Gulf of Lion Bay of Biscay 0.02768 0.00053 52.14126
Costa Calida Algarve Bay of Biscay 0.03963 0.00061 65.34353
Algarve Gulf of Lion Costa Calida 0.04409 0.00075 58.65375
Algarve Gulf of Lion Bay of Biscay 0.03291 0.00062 53.01836
Algarve Costa Calida Bay of Biscay 0.03103 0.00060 51.81058
Bay of Biscay Gulf of Lion Costa Calida 0.04026 0.00062 64.94020
Bay of Biscay Gulf of Lion Algarve 0.02704 0.00063 42.89278
Bay of Biscay Costa Calida Algarve 0.02902 0.00059 49.47201

Sarda sarda

Row

Sarda sarda

Row

Filtered

Admixed population Pop.1 Pop.2 f3 se Z
Gulf of Lion Costa Calida Algarve 0.00030 0.00025 1.22720
Gulf of Lion Costa Calida Bay of Biscay 0.00019 0.00023 0.83289
Gulf of Lion Algarve Bay of Biscay 0.00151 0.00025 5.99385
Costa Calida Gulf of Lion Algarve 0.00083 0.00025 3.38400
Costa Calida Gulf of Lion Bay of Biscay 0.00095 0.00025 3.73106
Costa Calida Algarve Bay of Biscay 0.00215 0.00027 7.83516
Algarve Gulf of Lion Costa Calida 0.00825 0.00026 32.29646
Algarve Gulf of Lion Bay of Biscay 0.00716 0.00026 27.83131
Algarve Costa Calida Bay of Biscay 0.00706 0.00026 27.09661
Bay of Biscay Gulf of Lion Costa Calida 0.00150 0.00025 6.04429
Bay of Biscay Gulf of Lion Algarve 0.00019 0.00026 0.72340
Bay of Biscay Costa Calida Algarve 0.00030 0.00026 1.14709

Unfiltered

Admixed population Pop.1 Pop.2 f3 se Z
Gulf of Lion Costa Calida Algarve 0.00452 0.00039 11.64356
Gulf of Lion Costa Calida Bay of Biscay 0.00425 0.00037 11.55092
Gulf of Lion Algarve Bay of Biscay 0.00560 0.00039 14.45901
Costa Calida Gulf of Lion Algarve 0.00484 0.00038 12.57825
Costa Calida Gulf of Lion Bay of Biscay 0.00503 0.00039 12.98362
Costa Calida Algarve Bay of Biscay 0.00615 0.00040 15.30620
Algarve Gulf of Lion Costa Calida 0.01196 0.00037 32.39424
Algarve Gulf of Lion Bay of Biscay 0.01099 0.00038 29.25193
Algarve Costa Calida Bay of Biscay 0.01073 0.00037 29.19831
Bay of Biscay Gulf of Lion Costa Calida 0.00569 0.00039 14.62001
Bay of Biscay Gulf of Lion Algarve 0.00441 0.00039 11.17654
Bay of Biscay Costa Calida Algarve 0.00465 0.00040 11.63823

Syngnathus typhle

Row

Syngnathus typhle

Row

Filtered

Admixed population Pop.1 Pop.2 f3 se Z
Gulf of Lion Costa Calida Algarve 0.05868 0.00231 25.38362
Gulf of Lion Costa Calida Bay of Biscay 0.05973 0.00241 24.80992
Gulf of Lion Algarve Bay of Biscay 0.17749 0.00308 57.62275
Costa Calida Gulf of Lion Algarve 0.08299 0.00328 25.26683
Costa Calida Gulf of Lion Bay of Biscay 0.08192 0.00312 26.29232
Costa Calida Algarve Bay of Biscay 0.20694 0.00385 53.77812
Algarve Gulf of Lion Costa Calida 0.15155 0.00170 89.12819
Algarve Gulf of Lion Bay of Biscay 0.01294 0.00113 11.49317
Algarve Costa Calida Bay of Biscay 0.01411 0.00133 10.57773
Bay of Biscay Gulf of Lion Costa Calida 1.02527 0.01570 65.28549
Bay of Biscay Gulf of Lion Algarve 0.71692 0.01171 61.23447
Bay of Biscay Costa Calida Algarve 0.71412 0.01169 61.11048

Unfiltered

Admixed population Pop.1 Pop.2 f3 se Z
Gulf of Lion Costa Calida Algarve 0.05968 0.00213 28.00246
Gulf of Lion Costa Calida Bay of Biscay 0.06076 0.00220 27.62541
Gulf of Lion Algarve Bay of Biscay 0.17479 0.00286 61.16379
Costa Calida Gulf of Lion Algarve 0.08576 0.00285 30.09766
Costa Calida Gulf of Lion Bay of Biscay 0.08479 0.00274 30.92939
Costa Calida Algarve Bay of Biscay 0.20531 0.00336 61.06793
Algarve Gulf of Lion Costa Calida 0.14832 0.00163 91.11819
Algarve Gulf of Lion Bay of Biscay 0.01533 0.00107 14.34685
Algarve Costa Calida Bay of Biscay 0.01634 0.00121 13.55467
Bay of Biscay Gulf of Lion Costa Calida 0.95238 0.01581 60.25649
Bay of Biscay Gulf of Lion Algarve 0.66602 0.01134 58.74951
Bay of Biscay Costa Calida Algarve 0.66294 0.01147 57.81981

Packages used

         reshape2           stringr           viridis       viridisLite           R.utils              R.oo 
          "1.4.4"           "1.4.1"           "0.6.2"           "0.4.1"          "2.11.0"          "1.24.0" 
      R.methodsS3        kableExtra       formattable               png            readxl            plotly 
          "1.8.1"           "1.3.4"           "0.2.1"           "0.1-7"           "1.3.1"          "4.10.0" 
            dplyr                DT           leaflet              ggsn           ggplot2 rnaturalearthdata 
         "1.0.10"            "0.20"           "2.1.1"           "0.5.0"           "3.4.0"           "0.1.0" 
    rnaturalearth                sf      RColorBrewer         rmarkdown     flexdashboard 
          "0.1.0"           "1.0-2"           "1.1-3"            "2.11"           "0.6.0" 
---
title: "f3"
author: "Pierre Barry"
date: "`r format(Sys.time(), '%d %B, %Y, %H:%M')`"
output: 
  flexdashboard::flex_dashboard:
    theme: paper
    orientation: rows
    social: menu
    source_code: embed
    vertical_layout: scroll
---

```{r global, include=FALSE}
list.of.packages <- c("RColorBrewer","reshape2","kableExtra","ggplot2","plotly")

for (i in list.of.packages){
  if (i %in% installed.packages()[,"Package"] == FALSE){
    install.packages(i)
  }
  eval(bquote(library(.(i))))
}
```

```{r, include = FALSE}
color_med_atl=data.frame(Location=c("Gulf of Lion","Costa Calida","Algarve","Bay of Biscay"),
                         Col=brewer.pal(n = 4, name = "RdBu"))
```

```{r, include = FALSE}
data = read.table(paste(path,"/output/pop_genomics/f3.csv",sep=""),header = TRUE, sep=",",dec=".")
data = data [,-1]

vcf_f3=cbind(data[,seq(2,ncol(data),by=3)])
vcf_f3=cbind(data[,1],vcf_f3)
colnames(vcf_f3)[1]="Species"
vcf_f3=melt(vcf_f3,id="Species")

vcf_f3_se=cbind(data[,seq(3,ncol(data),by=3)])
vcf_f3_se=cbind(data[,1],vcf_f3_se)
colnames(vcf_f3_se)[1]="Species"
vcf_f3_se=melt(vcf_f3_se,id="Species")

vcf_f3_z=cbind(data[,seq(4,ncol(data),by=3)])
vcf_f3_z=cbind(data[,1],vcf_f3_z)
colnames(vcf_f3_z)[1]="Species"
vcf_f3_z=melt(vcf_f3_z,id="Species")

vcf_f3=cbind(vcf_f3,vcf_f3_se$value,vcf_f3_z$value)
colnames(vcf_f3)[4]="se"
colnames(vcf_f3)[5]="z"
```

Atherina boyeri {data-navmenu="Species"}
=======================================================================

Row {.tabset data-height=50}
-----------------------
  
<center>

<font size="6">**Atherina boyeri**</font>

</center>

Row {.tabset data-height=2500}
-----------------------

### Filtered

```{r}
# Filtered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Aboye" & !grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop_admix=as.character(vcf_f3_sp$pop_admix)
vcf_f3_sp$pop_1=as.character(vcf_f3_sp$pop_1)
vcf_f3_sp$pop_2=as.character(vcf_f3_sp$pop_2)

vcf_f3_sp[1:3,1]<-cell_spec(vcf_f3_sp[1:3,1], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[4:6,1]<-cell_spec(vcf_f3_sp[4:6,1], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[7:9,1]<-cell_spec(vcf_f3_sp[7:9,1], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[10:12,1]<-cell_spec(vcf_f3_sp[10:12,1], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3], color = color_med_atl$Col[4], bold = F)

kbl(vcf_f3_sp,col.names = c("Admixed population",
                           "Pop.1",
                           "Pop.2",
                           "f3",
                           "se",
                           "Z")
    ,escape = F,align=c(rep('c',times=6))) %>%
  kable_classic ("striped","hover", full_width = T,html_font = "Cambria") %>%
  row_spec(which(vcf_f3_sp$value<0 & vcf_f3_sp$Z<(-3)), bold = T, color = "black")
```


```{r}
# Filtered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Aboye" & !grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop1_pop2=paste(vcf_f3_sp$pop_admix,";",vcf_f3_sp$pop_1,"-",vcf_f3_sp$pop_2,sep="")

vcf_f3_sp$pop1_pop2=factor(vcf_f3_sp$pop1_pop2,
                           levels=c(vcf_f3_sp$pop1_pop2))

def=c()
for (i in 1:nrow(vcf_f3_sp)){
  if (vcf_f3_sp$value[i]<0 & vcf_f3_sp$Z[i]<(-3)){
    def[i]="Negative"
  } else {
    def[i]="Zero"
  }
}
vcf_f3_sp$def=def


p<-ggplot(vcf_f3_sp,aes(x=pop1_pop2,y=value,fill=pop_admix))+
  geom_bar(stat="identity", aes(color=def))+
  geom_errorbar(aes(ymin=value-se, ymax=value+se),width=.2,
                 position=position_dodge(.9)) +
  theme_bw() + 
  scale_fill_manual(values=color_med_atl$Col)+
  scale_color_manual(breaks=c("Negative","Zero"),values=c("chartreuse4","white"))+
  theme(
          panel.grid.major = element_blank(),
          panel.grid.minor = element_blank(),
          axis.text.x = element_text(angle=45)
  ) +
  scale_x_discrete(labels=c("Gulf of Lion;Costa Calida-Algarve" = "Costa Calida-Algarve",
                            "Gulf of Lion;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Gulf of Lion;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Costa Calida;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Costa Calida;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Costa Calida;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Algarve;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Algarve;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Algarve;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Bay of Biscay;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Bay of Biscay;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Bay of Biscay;Costa Calida-Algarve" = "Costa Calida-Algarve"))+
  xlab("Pop1,Pop2")+
  ylab("f3")
p<-ggplotly(p,height=500)  %>% partial_bundle() 
p
```

### Unfiltered

```{r}
# Unfiltered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Aboye" & grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop_admix=as.character(vcf_f3_sp$pop_admix)
vcf_f3_sp$pop_1=as.character(vcf_f3_sp$pop_1)
vcf_f3_sp$pop_2=as.character(vcf_f3_sp$pop_2)

vcf_f3_sp[1:3,1]<-cell_spec(vcf_f3_sp[1:3,1], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[4:6,1]<-cell_spec(vcf_f3_sp[4:6,1], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[7:9,1]<-cell_spec(vcf_f3_sp[7:9,1], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[10:12,1]<-cell_spec(vcf_f3_sp[10:12,1], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3], color = color_med_atl$Col[4], bold = F)

kbl(vcf_f3_sp,col.names = c("Admixed population",
                           "Pop.1",
                           "Pop.2",
                           "f3",
                           "se",
                           "Z")
    ,escape = F,align=c(rep('c',times=6))) %>%
  kable_classic ("striped","hover", full_width = T,html_font = "Cambria") %>%
  row_spec(which(vcf_f3_sp$value<0 & vcf_f3_sp$Z<(-3)), bold = T, color = "black")
```

```{r}
# Unfiltered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Aboye" & grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop1_pop2=paste(vcf_f3_sp$pop_admix,";",vcf_f3_sp$pop_1,"-",vcf_f3_sp$pop_2,sep="")

vcf_f3_sp$pop1_pop2=factor(vcf_f3_sp$pop1_pop2,
                           levels=c(vcf_f3_sp$pop1_pop2))

def=c()
for (i in 1:nrow(vcf_f3_sp)){
  if (vcf_f3_sp$value[i]<0 & vcf_f3_sp$Z[i]<(-3)){
    def[i]="Negative"
  } else {
    def[i]="Zero"
  }
}
vcf_f3_sp$def=def


p<-ggplot(vcf_f3_sp,aes(x=pop1_pop2,y=value,fill=pop_admix))+
  geom_bar(stat="identity", aes(color=def))+
  geom_errorbar(aes(ymin=value-se, ymax=value+se),width=.2,
                 position=position_dodge(.9)) +
  theme_bw() + 
  scale_fill_manual(values=color_med_atl$Col)+
  scale_color_manual(breaks=c("Negative","Zero"),values=c("chartreuse4","white"))+
  theme(
          panel.grid.major = element_blank(),
          panel.grid.minor = element_blank(),
          axis.text.x = element_text(angle=45)
  ) +
  scale_x_discrete(labels=c("Gulf of Lion;Costa Calida-Algarve" = "Costa Calida-Algarve",
                            "Gulf of Lion;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Gulf of Lion;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Costa Calida;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Costa Calida;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Costa Calida;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Algarve;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Algarve;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Algarve;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Bay of Biscay;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Bay of Biscay;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Bay of Biscay;Costa Calida-Algarve" = "Costa Calida-Algarve"))+
  xlab("Pop1,Pop2")+
  ylab("f3")
p<-ggplotly(p,height=500)  %>% partial_bundle() 
p
```




Alosa fallax {data-navmenu="Species"}
=======================================================================

Row {.tabset data-height=50}
-----------------------
  
<center>

<font size="6">**Alosa fallax**</font>

</center>

Row {.tabset data-height=2500}
-----------------------

### Filtered

```{r}
# Filtered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Afall" & !grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop_admix=as.character(vcf_f3_sp$pop_admix)
vcf_f3_sp$pop_1=as.character(vcf_f3_sp$pop_1)
vcf_f3_sp$pop_2=as.character(vcf_f3_sp$pop_2)

vcf_f3_sp[1:3,1]<-cell_spec(vcf_f3_sp[1:3,1], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[4:6,1]<-cell_spec(vcf_f3_sp[4:6,1], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[7:9,1]<-cell_spec(vcf_f3_sp[7:9,1], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[10:12,1]<-cell_spec(vcf_f3_sp[10:12,1], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3], color = color_med_atl$Col[4], bold = F)

kbl(vcf_f3_sp,col.names = c("Admixed population",
                           "Pop.1",
                           "Pop.2",
                           "f3",
                           "se",
                           "Z")
    ,escape = F,align=c(rep('c',times=6))) %>%
  kable_classic ("striped","hover", full_width = T,html_font = "Cambria") %>%
  row_spec(which(vcf_f3_sp$value<0 & vcf_f3_sp$Z<(-3)), bold = T, color = "black")
```


```{r}
# Filtered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Afall" & !grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop1_pop2=paste(vcf_f3_sp$pop_admix,";",vcf_f3_sp$pop_1,"-",vcf_f3_sp$pop_2,sep="")

vcf_f3_sp$pop1_pop2=factor(vcf_f3_sp$pop1_pop2,
                           levels=c(vcf_f3_sp$pop1_pop2))

def=c()
for (i in 1:nrow(vcf_f3_sp)){
  if (is.na(vcf_f3_sp$value[i]) == F){
    if (vcf_f3_sp$value[i]<0 & vcf_f3_sp$Z[i]<(-3)){
      def[i]="Negative"
    } else {
      def[i]="Zero"
    }
  }
}
vcf_f3_sp$def=def


p<-ggplot(vcf_f3_sp,aes(x=pop1_pop2,y=value,fill=pop_admix))+
  geom_bar(stat="identity", aes(color=def))+
  geom_errorbar(aes(ymin=value-se, ymax=value+se),width=.2,
                 position=position_dodge(.9)) +
  theme_bw() + 
  scale_fill_manual(values=color_med_atl$Col)+
  scale_color_manual(breaks=c("Negative","Zero"),values=c("chartreuse4","white"))+
  theme(
          panel.grid.major = element_blank(),
          panel.grid.minor = element_blank(),
          axis.text.x = element_text(angle=45)
  ) +
  scale_x_discrete(labels=c("Gulf of Lion;Costa Calida-Algarve" = "Costa Calida-Algarve",
                            "Gulf of Lion;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Gulf of Lion;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Costa Calida;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Costa Calida;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Costa Calida;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Algarve;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Algarve;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Algarve;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Bay of Biscay;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Bay of Biscay;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Bay of Biscay;Costa Calida-Algarve" = "Costa Calida-Algarve"))+
  xlab("Pop1,Pop2")+
  ylab("f3")
p<-ggplotly(p,height=500)  %>% partial_bundle() 
p
```

### Unfiltered

```{r}
# Unfiltered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Afall" & grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop_admix=as.character(vcf_f3_sp$pop_admix)
vcf_f3_sp$pop_1=as.character(vcf_f3_sp$pop_1)
vcf_f3_sp$pop_2=as.character(vcf_f3_sp$pop_2)

vcf_f3_sp[1:3,1]<-cell_spec(vcf_f3_sp[1:3,1], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[4:6,1]<-cell_spec(vcf_f3_sp[4:6,1], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[7:9,1]<-cell_spec(vcf_f3_sp[7:9,1], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[10:12,1]<-cell_spec(vcf_f3_sp[10:12,1], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3], color = color_med_atl$Col[4], bold = F)

kbl(vcf_f3_sp,col.names = c("Admixed population",
                           "Pop.1",
                           "Pop.2",
                           "f3",
                           "se",
                           "Z")
    ,escape = F,align=c(rep('c',times=6))) %>%
  kable_classic ("striped","hover", full_width = T,html_font = "Cambria") %>%
  row_spec(which(vcf_f3_sp$value<0 & vcf_f3_sp$Z<(-3)), bold = T, color = "black")
```

```{r}
# Unfiltered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Afall" & grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop1_pop2=paste(vcf_f3_sp$pop_admix,";",vcf_f3_sp$pop_1,"-",vcf_f3_sp$pop_2,sep="")

vcf_f3_sp$pop1_pop2=factor(vcf_f3_sp$pop1_pop2,
                           levels=c(vcf_f3_sp$pop1_pop2))

def=c()
for (i in 1:nrow(vcf_f3_sp)){
  if (is.na(vcf_f3_sp$value[i]) == F){
    if (vcf_f3_sp$value[i]<0 & vcf_f3_sp$Z[i]<(-3)){
      def[i]="Negative"
    } else {
      def[i]="Zero"
    }
  }
}
vcf_f3_sp$def=def


p<-ggplot(vcf_f3_sp,aes(x=pop1_pop2,y=value,fill=pop_admix))+
  geom_bar(stat="identity", aes(color=def))+
  geom_errorbar(aes(ymin=value-se, ymax=value+se),width=.2,
                 position=position_dodge(.9)) +
  theme_bw() + 
  scale_fill_manual(values=color_med_atl$Col)+
  scale_color_manual(breaks=c("Negative","Zero"),values=c("chartreuse4","white"))+
  theme(
          panel.grid.major = element_blank(),
          panel.grid.minor = element_blank(),
          axis.text.x = element_text(angle=45)
  ) +
  scale_x_discrete(labels=c("Gulf of Lion;Costa Calida-Algarve" = "Costa Calida-Algarve",
                            "Gulf of Lion;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Gulf of Lion;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Costa Calida;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Costa Calida;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Costa Calida;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Algarve;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Algarve;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Algarve;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Bay of Biscay;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Bay of Biscay;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Bay of Biscay;Costa Calida-Algarve" = "Costa Calida-Algarve"))+
  xlab("Pop1,Pop2")+
  ylab("f3")
p<-ggplotly(p,height=500)  %>% partial_bundle() 
p
```




Coryphoblennius galerita {data-navmenu="Species"}
=======================================================================

Row {.tabset data-height=50}
-----------------------
  
<center>

<font size="6">**Coryphoblennius galerita**</font>

</center>

Row {.tabset data-height=2500}
-----------------------

### Filtered

```{r}
# Filtered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Cgale" & !grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop_admix=as.character(vcf_f3_sp$pop_admix)
vcf_f3_sp$pop_1=as.character(vcf_f3_sp$pop_1)
vcf_f3_sp$pop_2=as.character(vcf_f3_sp$pop_2)

vcf_f3_sp[1:3,1]<-cell_spec(vcf_f3_sp[1:3,1], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[4:6,1]<-cell_spec(vcf_f3_sp[4:6,1], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[7:9,1]<-cell_spec(vcf_f3_sp[7:9,1], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[10:12,1]<-cell_spec(vcf_f3_sp[10:12,1], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3], color = color_med_atl$Col[4], bold = F)

kbl(vcf_f3_sp,col.names = c("Admixed population",
                           "Pop.1",
                           "Pop.2",
                           "f3",
                           "se",
                           "Z")
    ,escape = F,align=c(rep('c',times=6))) %>%
  kable_classic ("striped","hover", full_width = T,html_font = "Cambria") %>%
  row_spec(which(vcf_f3_sp$value<0 & vcf_f3_sp$Z<(-3)), bold = T, color = "black")
```


```{r}
# Filtered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Cgale" & !grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop1_pop2=paste(vcf_f3_sp$pop_admix,";",vcf_f3_sp$pop_1,"-",vcf_f3_sp$pop_2,sep="")

vcf_f3_sp$pop1_pop2=factor(vcf_f3_sp$pop1_pop2,
                           levels=c(vcf_f3_sp$pop1_pop2))

def=c()
for (i in 1:nrow(vcf_f3_sp)){
  if (vcf_f3_sp$value[i]<0 & vcf_f3_sp$Z[i]<(-3)){
    def[i]="Negative"
  } else {
    def[i]="Zero"
  }
}
vcf_f3_sp$def=def


p<-ggplot(vcf_f3_sp,aes(x=pop1_pop2,y=value,fill=pop_admix))+
  geom_bar(stat="identity", aes(color=def))+
  geom_errorbar(aes(ymin=value-se, ymax=value+se),width=.2,
                 position=position_dodge(.9)) +
  theme_bw() + 
  scale_fill_manual(values=color_med_atl$Col)+
  scale_color_manual(breaks=c("Negative","Zero"),values=c("chartreuse4","white"))+
  theme(
          panel.grid.major = element_blank(),
          panel.grid.minor = element_blank(),
          axis.text.x = element_text(angle=45)
  ) +
  scale_x_discrete(labels=c("Gulf of Lion;Costa Calida-Algarve" = "Costa Calida-Algarve",
                            "Gulf of Lion;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Gulf of Lion;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Costa Calida;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Costa Calida;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Costa Calida;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Algarve;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Algarve;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Algarve;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Bay of Biscay;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Bay of Biscay;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Bay of Biscay;Costa Calida-Algarve" = "Costa Calida-Algarve"))+
  xlab("Pop1,Pop2")+
  ylab("f3")
p<-ggplotly(p,height=500)  %>% partial_bundle() 
p
```

### Unfiltered

```{r}
# Unfiltered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Cgale" & grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop_admix=as.character(vcf_f3_sp$pop_admix)
vcf_f3_sp$pop_1=as.character(vcf_f3_sp$pop_1)
vcf_f3_sp$pop_2=as.character(vcf_f3_sp$pop_2)

vcf_f3_sp[1:3,1]<-cell_spec(vcf_f3_sp[1:3,1], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[4:6,1]<-cell_spec(vcf_f3_sp[4:6,1], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[7:9,1]<-cell_spec(vcf_f3_sp[7:9,1], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[10:12,1]<-cell_spec(vcf_f3_sp[10:12,1], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3], color = color_med_atl$Col[4], bold = F)

kbl(vcf_f3_sp,col.names = c("Admixed population",
                           "Pop.1",
                           "Pop.2",
                           "f3",
                           "se",
                           "Z")
    ,escape = F,align=c(rep('c',times=6))) %>%
  kable_classic ("striped","hover", full_width = T,html_font = "Cambria") %>%
  row_spec(which(vcf_f3_sp$value<0 & vcf_f3_sp$Z<(-3)), bold = T, color = "black")
```

```{r}
# Unfiltered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Cgale" & grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop1_pop2=paste(vcf_f3_sp$pop_admix,";",vcf_f3_sp$pop_1,"-",vcf_f3_sp$pop_2,sep="")

vcf_f3_sp$pop1_pop2=factor(vcf_f3_sp$pop1_pop2,
                           levels=c(vcf_f3_sp$pop1_pop2))

def=c()
for (i in 1:nrow(vcf_f3_sp)){
  if (vcf_f3_sp$value[i]<0 & vcf_f3_sp$Z[i]<(-3)){
    def[i]="Negative"
  } else {
    def[i]="Zero"
  }
}
vcf_f3_sp$def=def


p<-ggplot(vcf_f3_sp,aes(x=pop1_pop2,y=value,fill=pop_admix))+
  geom_bar(stat="identity", aes(color=def))+
  geom_errorbar(aes(ymin=value-se, ymax=value+se),width=.2,
                 position=position_dodge(.9)) +
  theme_bw() + 
  scale_fill_manual(values=color_med_atl$Col)+
  scale_color_manual(breaks=c("Negative","Zero"),values=c("chartreuse4","white"))+
  theme(
          panel.grid.major = element_blank(),
          panel.grid.minor = element_blank(),
          axis.text.x = element_text(angle=45)
  ) +
  scale_x_discrete(labels=c("Gulf of Lion;Costa Calida-Algarve" = "Costa Calida-Algarve",
                            "Gulf of Lion;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Gulf of Lion;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Costa Calida;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Costa Calida;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Costa Calida;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Algarve;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Algarve;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Algarve;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Bay of Biscay;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Bay of Biscay;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Bay of Biscay;Costa Calida-Algarve" = "Costa Calida-Algarve"))+
  xlab("Pop1,Pop2")+
  ylab("f3")
p<-ggplotly(p,height=500)  %>% partial_bundle() 
p
```




Coris julis {data-navmenu="Species"}
=======================================================================

Row {.tabset data-height=50}
-----------------------
  
<center>

<font size="6">**Coris julis**</font>

</center>

Row {.tabset data-height=2500}
-----------------------

### Filtered

```{r}
# Filtered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Cjuli" & !grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop_admix=as.character(vcf_f3_sp$pop_admix)
vcf_f3_sp$pop_1=as.character(vcf_f3_sp$pop_1)
vcf_f3_sp$pop_2=as.character(vcf_f3_sp$pop_2)

vcf_f3_sp[1:3,1]<-cell_spec(vcf_f3_sp[1:3,1], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[4:6,1]<-cell_spec(vcf_f3_sp[4:6,1], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[7:9,1]<-cell_spec(vcf_f3_sp[7:9,1], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[10:12,1]<-cell_spec(vcf_f3_sp[10:12,1], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3], color = color_med_atl$Col[4], bold = F)

kbl(vcf_f3_sp,col.names = c("Admixed population",
                           "Pop.1",
                           "Pop.2",
                           "f3",
                           "se",
                           "Z")
    ,escape = F,align=c(rep('c',times=6))) %>%
  kable_classic ("striped","hover", full_width = T,html_font = "Cambria") %>%
  row_spec(which(vcf_f3_sp$value<0 & vcf_f3_sp$Z<(-3)), bold = T, color = "black")
```


```{r}
# Filtered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Cjuli" & !grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop1_pop2=paste(vcf_f3_sp$pop_admix,";",vcf_f3_sp$pop_1,"-",vcf_f3_sp$pop_2,sep="")

vcf_f3_sp$pop1_pop2=factor(vcf_f3_sp$pop1_pop2,
                           levels=c(vcf_f3_sp$pop1_pop2))

def=c()
for (i in 1:nrow(vcf_f3_sp)){
  if (vcf_f3_sp$value[i]<0 & vcf_f3_sp$Z[i]<(-3)){
    def[i]="Negative"
  } else {
    def[i]="Zero"
  }
}
vcf_f3_sp$def=def


p<-ggplot(vcf_f3_sp,aes(x=pop1_pop2,y=value,fill=pop_admix))+
  geom_bar(stat="identity", aes(color=def))+
  geom_errorbar(aes(ymin=value-se, ymax=value+se),width=.2,
                 position=position_dodge(.9)) +
  theme_bw() + 
  scale_fill_manual(values=color_med_atl$Col)+
  scale_color_manual(breaks=c("Negative","Zero"),values=c("chartreuse4","white"))+
  theme(
          panel.grid.major = element_blank(),
          panel.grid.minor = element_blank(),
          axis.text.x = element_text(angle=45)
  ) +
  scale_x_discrete(labels=c("Gulf of Lion;Costa Calida-Algarve" = "Costa Calida-Algarve",
                            "Gulf of Lion;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Gulf of Lion;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Costa Calida;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Costa Calida;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Costa Calida;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Algarve;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Algarve;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Algarve;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Bay of Biscay;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Bay of Biscay;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Bay of Biscay;Costa Calida-Algarve" = "Costa Calida-Algarve"))+
  xlab("Pop1,Pop2")+
  ylab("f3")
p<-ggplotly(p,height=500)  %>% partial_bundle() 
p
```

### Unfiltered

```{r}
# Unfiltered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Cjuli" & grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop_admix=as.character(vcf_f3_sp$pop_admix)
vcf_f3_sp$pop_1=as.character(vcf_f3_sp$pop_1)
vcf_f3_sp$pop_2=as.character(vcf_f3_sp$pop_2)

vcf_f3_sp[1:3,1]<-cell_spec(vcf_f3_sp[1:3,1], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[4:6,1]<-cell_spec(vcf_f3_sp[4:6,1], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[7:9,1]<-cell_spec(vcf_f3_sp[7:9,1], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[10:12,1]<-cell_spec(vcf_f3_sp[10:12,1], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3], color = color_med_atl$Col[4], bold = F)

kbl(vcf_f3_sp,col.names = c("Admixed population",
                           "Pop.1",
                           "Pop.2",
                           "f3",
                           "se",
                           "Z")
    ,escape = F,align=c(rep('c',times=6))) %>%
  kable_classic ("striped","hover", full_width = T,html_font = "Cambria") %>%
  row_spec(which(vcf_f3_sp$value<0 & vcf_f3_sp$Z<(-3)), bold = T, color = "black")
```

```{r}
# Unfiltered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Cjuli" & grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop1_pop2=paste(vcf_f3_sp$pop_admix,";",vcf_f3_sp$pop_1,"-",vcf_f3_sp$pop_2,sep="")

vcf_f3_sp$pop1_pop2=factor(vcf_f3_sp$pop1_pop2,
                           levels=c(vcf_f3_sp$pop1_pop2))

def=c()
for (i in 1:nrow(vcf_f3_sp)){
  if (vcf_f3_sp$value[i]<0 & vcf_f3_sp$Z[i]<(-3)){
    def[i]="Negative"
  } else {
    def[i]="Zero"
  }
}
vcf_f3_sp$def=def


p<-ggplot(vcf_f3_sp,aes(x=pop1_pop2,y=value,fill=pop_admix))+
  geom_bar(stat="identity", aes(color=def))+
  geom_errorbar(aes(ymin=value-se, ymax=value+se),width=.2,
                 position=position_dodge(.9)) +
  theme_bw() + 
  scale_fill_manual(values=color_med_atl$Col)+
  scale_color_manual(breaks=c("Negative","Zero"),values=c("chartreuse4","white"))+
  theme(
          panel.grid.major = element_blank(),
          panel.grid.minor = element_blank(),
          axis.text.x = element_text(angle=45)
  ) +
  scale_x_discrete(labels=c("Gulf of Lion;Costa Calida-Algarve" = "Costa Calida-Algarve",
                            "Gulf of Lion;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Gulf of Lion;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Costa Calida;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Costa Calida;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Costa Calida;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Algarve;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Algarve;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Algarve;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Bay of Biscay;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Bay of Biscay;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Bay of Biscay;Costa Calida-Algarve" = "Costa Calida-Algarve"))+
  xlab("Pop1,Pop2")+
  ylab("f3")
p<-ggplotly(p,height=500)  %>% partial_bundle() 
p
```



Dicentrarchus labrax {data-navmenu="Species"}
=======================================================================

Row {.tabset data-height=50}
-----------------------
  
<center>

<font size="6">**Dicentrarchus labrax**</font>

</center>

Row {.tabset data-height=2500}
-----------------------

### Filtered

```{r}
# Filtered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Dlabr" & !grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop_admix=as.character(vcf_f3_sp$pop_admix)
vcf_f3_sp$pop_1=as.character(vcf_f3_sp$pop_1)
vcf_f3_sp$pop_2=as.character(vcf_f3_sp$pop_2)

vcf_f3_sp[1:3,1]<-cell_spec(vcf_f3_sp[1:3,1], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[4:6,1]<-cell_spec(vcf_f3_sp[4:6,1], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[7:9,1]<-cell_spec(vcf_f3_sp[7:9,1], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[10:12,1]<-cell_spec(vcf_f3_sp[10:12,1], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3], color = color_med_atl$Col[4], bold = F)

kbl(vcf_f3_sp,col.names = c("Admixed population",
                           "Pop.1",
                           "Pop.2",
                           "f3",
                           "se",
                           "Z")
    ,escape = F,align=c(rep('c',times=6))) %>%
  kable_classic ("striped","hover", full_width = T,html_font = "Cambria") %>%
  row_spec(which(vcf_f3_sp$value<0 & vcf_f3_sp$Z<(-3)), bold = T, color = "black")
```


```{r}
# Filtered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Dlabr" & !grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop1_pop2=paste(vcf_f3_sp$pop_admix,";",vcf_f3_sp$pop_1,"-",vcf_f3_sp$pop_2,sep="")

vcf_f3_sp$pop1_pop2=factor(vcf_f3_sp$pop1_pop2,
                           levels=c(vcf_f3_sp$pop1_pop2))

def=c()
for (i in 1:nrow(vcf_f3_sp)){
  if (vcf_f3_sp$value[i]<0 & vcf_f3_sp$Z[i]<(-3)){
    def[i]="Negative"
  } else {
    def[i]="Zero"
  }
}
vcf_f3_sp$def=def


p<-ggplot(vcf_f3_sp,aes(x=pop1_pop2,y=value,fill=pop_admix))+
  geom_bar(stat="identity", aes(color=def))+
  geom_errorbar(aes(ymin=value-se, ymax=value+se),width=.2,
                 position=position_dodge(.9)) +
  theme_bw() + 
  scale_fill_manual(values=color_med_atl$Col)+
  scale_color_manual(breaks=c("Negative","Zero"),values=c("chartreuse4","white"))+
  theme(
          panel.grid.major = element_blank(),
          panel.grid.minor = element_blank(),
          axis.text.x = element_text(angle=45)
  ) +
  scale_x_discrete(labels=c("Gulf of Lion;Costa Calida-Algarve" = "Costa Calida-Algarve",
                            "Gulf of Lion;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Gulf of Lion;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Costa Calida;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Costa Calida;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Costa Calida;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Algarve;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Algarve;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Algarve;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Bay of Biscay;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Bay of Biscay;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Bay of Biscay;Costa Calida-Algarve" = "Costa Calida-Algarve"))+
  xlab("Pop1,Pop2")+
  ylab("f3")
p<-ggplotly(p,height=500)  %>% partial_bundle() 
p
```

### Unfiltered

```{r}
# Unfiltered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Dlabr" & grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop_admix=as.character(vcf_f3_sp$pop_admix)
vcf_f3_sp$pop_1=as.character(vcf_f3_sp$pop_1)
vcf_f3_sp$pop_2=as.character(vcf_f3_sp$pop_2)

vcf_f3_sp[1:3,1]<-cell_spec(vcf_f3_sp[1:3,1], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[4:6,1]<-cell_spec(vcf_f3_sp[4:6,1], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[7:9,1]<-cell_spec(vcf_f3_sp[7:9,1], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[10:12,1]<-cell_spec(vcf_f3_sp[10:12,1], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3], color = color_med_atl$Col[4], bold = F)

kbl(vcf_f3_sp,col.names = c("Admixed population",
                           "Pop.1",
                           "Pop.2",
                           "f3",
                           "se",
                           "Z")
    ,escape = F,align=c(rep('c',times=6))) %>%
  kable_classic ("striped","hover", full_width = T,html_font = "Cambria") %>%
  row_spec(which(vcf_f3_sp$value<0 & vcf_f3_sp$Z<(-3)), bold = T, color = "black")
```

```{r}
# Unfiltered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Dlabr" & grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop1_pop2=paste(vcf_f3_sp$pop_admix,";",vcf_f3_sp$pop_1,"-",vcf_f3_sp$pop_2,sep="")

vcf_f3_sp$pop1_pop2=factor(vcf_f3_sp$pop1_pop2,
                           levels=c(vcf_f3_sp$pop1_pop2))

def=c()
for (i in 1:nrow(vcf_f3_sp)){
  if (vcf_f3_sp$value[i]<0 & vcf_f3_sp$Z[i]<(-3)){
    def[i]="Negative"
  } else {
    def[i]="Zero"
  }
}
vcf_f3_sp$def=def


p<-ggplot(vcf_f3_sp,aes(x=pop1_pop2,y=value,fill=pop_admix))+
  geom_bar(stat="identity", aes(color=def))+
  geom_errorbar(aes(ymin=value-se, ymax=value+se),width=.2,
                 position=position_dodge(.9)) +
  theme_bw() + 
  scale_fill_manual(values=color_med_atl$Col)+
  scale_color_manual(breaks=c("Negative","Zero"),values=c("chartreuse4","white"))+
  theme(
          panel.grid.major = element_blank(),
          panel.grid.minor = element_blank(),
          axis.text.x = element_text(angle=45)
  ) +
  scale_x_discrete(labels=c("Gulf of Lion;Costa Calida-Algarve" = "Costa Calida-Algarve",
                            "Gulf of Lion;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Gulf of Lion;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Costa Calida;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Costa Calida;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Costa Calida;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Algarve;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Algarve;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Algarve;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Bay of Biscay;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Bay of Biscay;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Bay of Biscay;Costa Calida-Algarve" = "Costa Calida-Algarve"))+
  xlab("Pop1,Pop2")+
  ylab("f3")
p<-ggplotly(p,height=500)  %>% partial_bundle() 
p
```



Diplodus puntazzo {data-navmenu="Species"}
=======================================================================

Row {.tabset data-height=50}
-----------------------
  
<center>

<font size="6">**Diplodus puntazzo**</font>

</center>

Row {.tabset data-height=2500}
-----------------------

### Filtered

```{r}
# Filtered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Dpunt" & !grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop_admix=as.character(vcf_f3_sp$pop_admix)
vcf_f3_sp$pop_1=as.character(vcf_f3_sp$pop_1)
vcf_f3_sp$pop_2=as.character(vcf_f3_sp$pop_2)

vcf_f3_sp[1:3,1]<-cell_spec(vcf_f3_sp[1:3,1], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[4:6,1]<-cell_spec(vcf_f3_sp[4:6,1], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[7:9,1]<-cell_spec(vcf_f3_sp[7:9,1], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[10:12,1]<-cell_spec(vcf_f3_sp[10:12,1], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3], color = color_med_atl$Col[4], bold = F)

kbl(vcf_f3_sp,col.names = c("Admixed population",
                           "Pop.1",
                           "Pop.2",
                           "f3",
                           "se",
                           "Z")
    ,escape = F,align=c(rep('c',times=6))) %>%
  kable_classic ("striped","hover", full_width = T,html_font = "Cambria") %>%
  row_spec(which(vcf_f3_sp$value<0 & vcf_f3_sp$Z<(-3)), bold = T, color = "black")
```


```{r}
# Filtered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Dpunt" & !grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop1_pop2=paste(vcf_f3_sp$pop_admix,";",vcf_f3_sp$pop_1,"-",vcf_f3_sp$pop_2,sep="")

vcf_f3_sp$pop1_pop2=factor(vcf_f3_sp$pop1_pop2,
                           levels=c(vcf_f3_sp$pop1_pop2))

def=c()
for (i in 1:nrow(vcf_f3_sp)){
  if (vcf_f3_sp$value[i]<0 & vcf_f3_sp$Z[i]<(-3)){
    def[i]="Negative"
  } else {
    def[i]="Zero"
  }
}
vcf_f3_sp$def=def


p<-ggplot(vcf_f3_sp,aes(x=pop1_pop2,y=value,fill=pop_admix))+
  geom_bar(stat="identity", aes(color=def))+
  geom_errorbar(aes(ymin=value-se, ymax=value+se),width=.2,
                 position=position_dodge(.9)) +
  theme_bw() + 
  scale_fill_manual(values=color_med_atl$Col)+
  scale_color_manual(breaks=c("Negative","Zero"),values=c("chartreuse4","white"))+
  theme(
          panel.grid.major = element_blank(),
          panel.grid.minor = element_blank(),
          axis.text.x = element_text(angle=45)
  ) +
  scale_x_discrete(labels=c("Gulf of Lion;Costa Calida-Algarve" = "Costa Calida-Algarve",
                            "Gulf of Lion;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Gulf of Lion;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Costa Calida;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Costa Calida;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Costa Calida;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Algarve;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Algarve;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Algarve;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Bay of Biscay;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Bay of Biscay;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Bay of Biscay;Costa Calida-Algarve" = "Costa Calida-Algarve"))+
  xlab("Pop1,Pop2")+
  ylab("f3")
p<-ggplotly(p,height=500)  %>% partial_bundle() 
p
```

### Unfiltered

```{r}
# Unfiltered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Dpunt" & grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop_admix=as.character(vcf_f3_sp$pop_admix)
vcf_f3_sp$pop_1=as.character(vcf_f3_sp$pop_1)
vcf_f3_sp$pop_2=as.character(vcf_f3_sp$pop_2)

vcf_f3_sp[1:3,1]<-cell_spec(vcf_f3_sp[1:3,1], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[4:6,1]<-cell_spec(vcf_f3_sp[4:6,1], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[7:9,1]<-cell_spec(vcf_f3_sp[7:9,1], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[10:12,1]<-cell_spec(vcf_f3_sp[10:12,1], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3], color = color_med_atl$Col[4], bold = F)

kbl(vcf_f3_sp,col.names = c("Admixed population",
                           "Pop.1",
                           "Pop.2",
                           "f3",
                           "se",
                           "Z")
    ,escape = F,align=c(rep('c',times=6))) %>%
  kable_classic ("striped","hover", full_width = T,html_font = "Cambria") %>%
  row_spec(which(vcf_f3_sp$value<0 & vcf_f3_sp$Z<(-3)), bold = T, color = "black")
```

```{r}
# Unfiltered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Dpunt" & grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop1_pop2=paste(vcf_f3_sp$pop_admix,";",vcf_f3_sp$pop_1,"-",vcf_f3_sp$pop_2,sep="")

vcf_f3_sp$pop1_pop2=factor(vcf_f3_sp$pop1_pop2,
                           levels=c(vcf_f3_sp$pop1_pop2))

def=c()
for (i in 1:nrow(vcf_f3_sp)){
  if (vcf_f3_sp$value[i]<0 & vcf_f3_sp$Z[i]<(-3)){
    def[i]="Negative"
  } else {
    def[i]="Zero"
  }
}
vcf_f3_sp$def=def


p<-ggplot(vcf_f3_sp,aes(x=pop1_pop2,y=value,fill=pop_admix))+
  geom_bar(stat="identity", aes(color=def))+
  geom_errorbar(aes(ymin=value-se, ymax=value+se),width=.2,
                 position=position_dodge(.9)) +
  theme_bw() + 
  scale_fill_manual(values=color_med_atl$Col)+
  scale_color_manual(breaks=c("Negative","Zero"),values=c("chartreuse4","white"))+
  theme(
          panel.grid.major = element_blank(),
          panel.grid.minor = element_blank(),
          axis.text.x = element_text(angle=45)
  ) +
  scale_x_discrete(labels=c("Gulf of Lion;Costa Calida-Algarve" = "Costa Calida-Algarve",
                            "Gulf of Lion;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Gulf of Lion;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Costa Calida;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Costa Calida;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Costa Calida;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Algarve;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Algarve;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Algarve;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Bay of Biscay;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Bay of Biscay;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Bay of Biscay;Costa Calida-Algarve" = "Costa Calida-Algarve"))+
  xlab("Pop1,Pop2")+
  ylab("f3")
p<-ggplotly(p,height=500)  %>% partial_bundle() 
p
```



Gobius niger {data-navmenu="Species"}
=======================================================================

Row {.tabset data-height=50}
-----------------------
  
<center>

<font size="6">**Gobius niger**</font>

</center>

Row {.tabset data-height=2500}
-----------------------

### Filtered

```{r}
# Filtered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Gnige" & !grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop_admix=as.character(vcf_f3_sp$pop_admix)
vcf_f3_sp$pop_1=as.character(vcf_f3_sp$pop_1)
vcf_f3_sp$pop_2=as.character(vcf_f3_sp$pop_2)

vcf_f3_sp[1:3,1]<-cell_spec(vcf_f3_sp[1:3,1], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[4:6,1]<-cell_spec(vcf_f3_sp[4:6,1], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[7:9,1]<-cell_spec(vcf_f3_sp[7:9,1], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[10:12,1]<-cell_spec(vcf_f3_sp[10:12,1], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3], color = color_med_atl$Col[4], bold = F)

kbl(vcf_f3_sp,col.names = c("Admixed population",
                           "Pop.1",
                           "Pop.2",
                           "f3",
                           "se",
                           "Z")
    ,escape = F,align=c(rep('c',times=6))) %>%
  kable_classic ("striped","hover", full_width = T,html_font = "Cambria") %>%
  row_spec(which(vcf_f3_sp$value<0 & vcf_f3_sp$Z<(-3)), bold = T, color = "black")
```


```{r}
# Filtered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Gnige" & !grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop1_pop2=paste(vcf_f3_sp$pop_admix,";",vcf_f3_sp$pop_1,"-",vcf_f3_sp$pop_2,sep="")

vcf_f3_sp$pop1_pop2=factor(vcf_f3_sp$pop1_pop2,
                           levels=c(vcf_f3_sp$pop1_pop2))

def=c()
for (i in 1:nrow(vcf_f3_sp)){
  if (vcf_f3_sp$value[i]<0 & vcf_f3_sp$Z[i]<(-3)){
    def[i]="Negative"
  } else {
    def[i]="Zero"
  }
}
vcf_f3_sp$def=def


p<-ggplot(vcf_f3_sp,aes(x=pop1_pop2,y=value,fill=pop_admix))+
  geom_bar(stat="identity", aes(color=def))+
  geom_errorbar(aes(ymin=value-se, ymax=value+se),width=.2,
                 position=position_dodge(.9)) +
  theme_bw() + 
  scale_fill_manual(values=color_med_atl$Col)+
  scale_color_manual(breaks=c("Negative","Zero"),values=c("chartreuse4","white"))+
  theme(
          panel.grid.major = element_blank(),
          panel.grid.minor = element_blank(),
          axis.text.x = element_text(angle=45)
  ) +
  scale_x_discrete(labels=c("Gulf of Lion;Costa Calida-Algarve" = "Costa Calida-Algarve",
                            "Gulf of Lion;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Gulf of Lion;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Costa Calida;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Costa Calida;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Costa Calida;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Algarve;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Algarve;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Algarve;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Bay of Biscay;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Bay of Biscay;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Bay of Biscay;Costa Calida-Algarve" = "Costa Calida-Algarve"))+
  xlab("Pop1,Pop2")+
  ylab("f3")
p<-ggplotly(p,height=500)  %>% partial_bundle() 
p
```

### Unfiltered

```{r}
# Unfiltered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Gnige" & grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop_admix=as.character(vcf_f3_sp$pop_admix)
vcf_f3_sp$pop_1=as.character(vcf_f3_sp$pop_1)
vcf_f3_sp$pop_2=as.character(vcf_f3_sp$pop_2)

vcf_f3_sp[1:3,1]<-cell_spec(vcf_f3_sp[1:3,1], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[4:6,1]<-cell_spec(vcf_f3_sp[4:6,1], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[7:9,1]<-cell_spec(vcf_f3_sp[7:9,1], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[10:12,1]<-cell_spec(vcf_f3_sp[10:12,1], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3], color = color_med_atl$Col[4], bold = F)

kbl(vcf_f3_sp,col.names = c("Admixed population",
                           "Pop.1",
                           "Pop.2",
                           "f3",
                           "se",
                           "Z")
    ,escape = F,align=c(rep('c',times=6))) %>%
  kable_classic ("striped","hover", full_width = T,html_font = "Cambria") %>%
  row_spec(which(vcf_f3_sp$value<0 & vcf_f3_sp$Z<(-3)), bold = T, color = "black")
```

```{r}
# Unfiltered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Gnige" & grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop1_pop2=paste(vcf_f3_sp$pop_admix,";",vcf_f3_sp$pop_1,"-",vcf_f3_sp$pop_2,sep="")

vcf_f3_sp$pop1_pop2=factor(vcf_f3_sp$pop1_pop2,
                           levels=c(vcf_f3_sp$pop1_pop2))

def=c()
for (i in 1:nrow(vcf_f3_sp)){
  if (vcf_f3_sp$value[i]<0 & vcf_f3_sp$Z[i]<(-3)){
    def[i]="Negative"
  } else {
    def[i]="Zero"
  }
}
vcf_f3_sp$def=def


p<-ggplot(vcf_f3_sp,aes(x=pop1_pop2,y=value,fill=pop_admix))+
  geom_bar(stat="identity", aes(color=def))+
  geom_errorbar(aes(ymin=value-se, ymax=value+se),width=.2,
                 position=position_dodge(.9)) +
  theme_bw() + 
  scale_fill_manual(values=color_med_atl$Col)+
  scale_color_manual(breaks=c("Negative","Zero"),values=c("chartreuse4","white"))+
  theme(
          panel.grid.major = element_blank(),
          panel.grid.minor = element_blank(),
          axis.text.x = element_text(angle=45)
  ) +
  scale_x_discrete(labels=c("Gulf of Lion;Costa Calida-Algarve" = "Costa Calida-Algarve",
                            "Gulf of Lion;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Gulf of Lion;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Costa Calida;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Costa Calida;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Costa Calida;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Algarve;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Algarve;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Algarve;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Bay of Biscay;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Bay of Biscay;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Bay of Biscay;Costa Calida-Algarve" = "Costa Calida-Algarve"))+
  xlab("Pop1,Pop2")+
  ylab("f3")
p<-ggplotly(p,height=500)  %>% partial_bundle() 
p
```




Hippocampus guttulatus {data-navmenu="Species"}
=======================================================================

Row {.tabset data-height=50}
-----------------------
  
<center>

<font size="6">**Hippocampus guttulatus**</font>

</center>

Row {.tabset data-height=2500}
-----------------------

### Filtered

```{r}
# Filtered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Hgutt" & !grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop_admix=as.character(vcf_f3_sp$pop_admix)
vcf_f3_sp$pop_1=as.character(vcf_f3_sp$pop_1)
vcf_f3_sp$pop_2=as.character(vcf_f3_sp$pop_2)

vcf_f3_sp[1:3,1]<-cell_spec(vcf_f3_sp[1:3,1], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[4:6,1]<-cell_spec(vcf_f3_sp[4:6,1], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[7:9,1]<-cell_spec(vcf_f3_sp[7:9,1], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[10:12,1]<-cell_spec(vcf_f3_sp[10:12,1], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3], color = color_med_atl$Col[4], bold = F)

kbl(vcf_f3_sp,col.names = c("Admixed population",
                           "Pop.1",
                           "Pop.2",
                           "f3",
                           "se",
                           "Z")
    ,escape = F,align=c(rep('c',times=6))) %>%
  kable_classic ("striped","hover", full_width = T,html_font = "Cambria") %>%
  row_spec(which(vcf_f3_sp$value<0 & vcf_f3_sp$Z<(-3)), bold = T, color = "black")
```


```{r}
# Filtered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Hgutt" & !grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop1_pop2=paste(vcf_f3_sp$pop_admix,";",vcf_f3_sp$pop_1,"-",vcf_f3_sp$pop_2,sep="")

vcf_f3_sp$pop1_pop2=factor(vcf_f3_sp$pop1_pop2,
                           levels=c(vcf_f3_sp$pop1_pop2))

def=c()
for (i in 1:nrow(vcf_f3_sp)){
  if (vcf_f3_sp$value[i]<0 & vcf_f3_sp$Z[i]<(-3)){
    def[i]="Negative"
  } else {
    def[i]="Zero"
  }
}
vcf_f3_sp$def=def


p<-ggplot(vcf_f3_sp,aes(x=pop1_pop2,y=value,fill=pop_admix))+
  geom_bar(stat="identity", aes(color=def))+
  geom_errorbar(aes(ymin=value-se, ymax=value+se),width=.2,
                 position=position_dodge(.9)) +
  theme_bw() + 
  scale_fill_manual(values=color_med_atl$Col)+
  scale_color_manual(breaks=c("Negative","Zero"),values=c("chartreuse4","white"))+
  theme(
          panel.grid.major = element_blank(),
          panel.grid.minor = element_blank(),
          axis.text.x = element_text(angle=45)
  ) +
  scale_x_discrete(labels=c("Gulf of Lion;Costa Calida-Algarve" = "Costa Calida-Algarve",
                            "Gulf of Lion;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Gulf of Lion;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Costa Calida;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Costa Calida;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Costa Calida;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Algarve;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Algarve;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Algarve;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Bay of Biscay;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Bay of Biscay;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Bay of Biscay;Costa Calida-Algarve" = "Costa Calida-Algarve"))+
  xlab("Pop1,Pop2")+
  ylab("f3")
p<-ggplotly(p,height=500)  %>% partial_bundle() 
p
```

### Unfiltered

```{r}
# Unfiltered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Hgutt" & grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop_admix=as.character(vcf_f3_sp$pop_admix)
vcf_f3_sp$pop_1=as.character(vcf_f3_sp$pop_1)
vcf_f3_sp$pop_2=as.character(vcf_f3_sp$pop_2)

vcf_f3_sp[1:3,1]<-cell_spec(vcf_f3_sp[1:3,1], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[4:6,1]<-cell_spec(vcf_f3_sp[4:6,1], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[7:9,1]<-cell_spec(vcf_f3_sp[7:9,1], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[10:12,1]<-cell_spec(vcf_f3_sp[10:12,1], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3], color = color_med_atl$Col[4], bold = F)

kbl(vcf_f3_sp,col.names = c("Admixed population",
                           "Pop.1",
                           "Pop.2",
                           "f3",
                           "se",
                           "Z")
    ,escape = F,align=c(rep('c',times=6))) %>%
  kable_classic ("striped","hover", full_width = T,html_font = "Cambria") %>%
  row_spec(which(vcf_f3_sp$value<0 & vcf_f3_sp$Z<(-3)), bold = T, color = "black")
```

```{r}
# Unfiltered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Hgutt" & grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop1_pop2=paste(vcf_f3_sp$pop_admix,";",vcf_f3_sp$pop_1,"-",vcf_f3_sp$pop_2,sep="")

vcf_f3_sp$pop1_pop2=factor(vcf_f3_sp$pop1_pop2,
                           levels=c(vcf_f3_sp$pop1_pop2))

def=c()
for (i in 1:nrow(vcf_f3_sp)){
  if (vcf_f3_sp$value[i]<0 & vcf_f3_sp$Z[i]<(-3)){
    def[i]="Negative"
  } else {
    def[i]="Zero"
  }
}
vcf_f3_sp$def=def


p<-ggplot(vcf_f3_sp,aes(x=pop1_pop2,y=value,fill=pop_admix))+
  geom_bar(stat="identity", aes(color=def))+
  geom_errorbar(aes(ymin=value-se, ymax=value+se),width=.2,
                 position=position_dodge(.9)) +
  theme_bw() + 
  scale_fill_manual(values=color_med_atl$Col)+
  scale_color_manual(breaks=c("Negative","Zero"),values=c("chartreuse4","white"))+
  theme(
          panel.grid.major = element_blank(),
          panel.grid.minor = element_blank(),
          axis.text.x = element_text(angle=45)
  ) +
  scale_x_discrete(labels=c("Gulf of Lion;Costa Calida-Algarve" = "Costa Calida-Algarve",
                            "Gulf of Lion;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Gulf of Lion;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Costa Calida;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Costa Calida;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Costa Calida;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Algarve;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Algarve;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Algarve;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Bay of Biscay;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Bay of Biscay;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Bay of Biscay;Costa Calida-Algarve" = "Costa Calida-Algarve"))+
  xlab("Pop1,Pop2")+
  ylab("f3")
p<-ggplotly(p,height=500)  %>% partial_bundle() 
p
```



Lophius budegassa {data-navmenu="Species"}
=======================================================================

Row {.tabset data-height=50}
-----------------------
  
<center>

<font size="6">**Lophius budegassa**</font>

</center>

Row {.tabset data-height=2500}
-----------------------

### Filtered

```{r}
# Filtered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Lbude" & !grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop_admix=as.character(vcf_f3_sp$pop_admix)
vcf_f3_sp$pop_1=as.character(vcf_f3_sp$pop_1)
vcf_f3_sp$pop_2=as.character(vcf_f3_sp$pop_2)

vcf_f3_sp[1:3,1]<-cell_spec(vcf_f3_sp[1:3,1], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[4:6,1]<-cell_spec(vcf_f3_sp[4:6,1], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[7:9,1]<-cell_spec(vcf_f3_sp[7:9,1], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[10:12,1]<-cell_spec(vcf_f3_sp[10:12,1], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3], color = color_med_atl$Col[4], bold = F)

kbl(vcf_f3_sp,col.names = c("Admixed population",
                           "Pop.1",
                           "Pop.2",
                           "f3",
                           "se",
                           "Z")
    ,escape = F,align=c(rep('c',times=6))) %>%
  kable_classic ("striped","hover", full_width = T,html_font = "Cambria") %>%
  row_spec(which(vcf_f3_sp$value<0 & vcf_f3_sp$Z<(-3)), bold = T, color = "black")
```


```{r}
# Filtered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Lbude" & !grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop1_pop2=paste(vcf_f3_sp$pop_admix,";",vcf_f3_sp$pop_1,"-",vcf_f3_sp$pop_2,sep="")

vcf_f3_sp$pop1_pop2=factor(vcf_f3_sp$pop1_pop2,
                           levels=c(vcf_f3_sp$pop1_pop2))

def=c()
for (i in 1:nrow(vcf_f3_sp)){
  if (vcf_f3_sp$value[i]<0 & vcf_f3_sp$Z[i]<(-3)){
    def[i]="Negative"
  } else {
    def[i]="Zero"
  }
}
vcf_f3_sp$def=def


p<-ggplot(vcf_f3_sp,aes(x=pop1_pop2,y=value,fill=pop_admix))+
  geom_bar(stat="identity", aes(color=def))+
  geom_errorbar(aes(ymin=value-se, ymax=value+se),width=.2,
                 position=position_dodge(.9)) +
  theme_bw() + 
  scale_fill_manual(values=color_med_atl$Col)+
  scale_color_manual(breaks=c("Negative","Zero"),values=c("chartreuse4","white"))+
  theme(
          panel.grid.major = element_blank(),
          panel.grid.minor = element_blank(),
          axis.text.x = element_text(angle=45)
  ) +
  scale_x_discrete(labels=c("Gulf of Lion;Costa Calida-Algarve" = "Costa Calida-Algarve",
                            "Gulf of Lion;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Gulf of Lion;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Costa Calida;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Costa Calida;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Costa Calida;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Algarve;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Algarve;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Algarve;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Bay of Biscay;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Bay of Biscay;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Bay of Biscay;Costa Calida-Algarve" = "Costa Calida-Algarve"))+
  xlab("Pop1,Pop2")+
  ylab("f3")
p<-ggplotly(p,height=500)  %>% partial_bundle() 
p
```

### Unfiltered

```{r}
# Unfiltered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Lbude" & grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop_admix=as.character(vcf_f3_sp$pop_admix)
vcf_f3_sp$pop_1=as.character(vcf_f3_sp$pop_1)
vcf_f3_sp$pop_2=as.character(vcf_f3_sp$pop_2)

vcf_f3_sp[1:3,1]<-cell_spec(vcf_f3_sp[1:3,1], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[4:6,1]<-cell_spec(vcf_f3_sp[4:6,1], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[7:9,1]<-cell_spec(vcf_f3_sp[7:9,1], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[10:12,1]<-cell_spec(vcf_f3_sp[10:12,1], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3], color = color_med_atl$Col[4], bold = F)

kbl(vcf_f3_sp,col.names = c("Admixed population",
                           "Pop.1",
                           "Pop.2",
                           "f3",
                           "se",
                           "Z")
    ,escape = F,align=c(rep('c',times=6))) %>%
  kable_classic ("striped","hover", full_width = T,html_font = "Cambria") %>%
  row_spec(which(vcf_f3_sp$value<0 & vcf_f3_sp$Z<(-3)), bold = T, color = "black")
```

```{r}
# Unfiltered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Lbude" & grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop1_pop2=paste(vcf_f3_sp$pop_admix,";",vcf_f3_sp$pop_1,"-",vcf_f3_sp$pop_2,sep="")

vcf_f3_sp$pop1_pop2=factor(vcf_f3_sp$pop1_pop2,
                           levels=c(vcf_f3_sp$pop1_pop2))

def=c()
for (i in 1:nrow(vcf_f3_sp)){
  if (vcf_f3_sp$value[i]<0 & vcf_f3_sp$Z[i]<(-3)){
    def[i]="Negative"
  } else {
    def[i]="Zero"
  }
}
vcf_f3_sp$def=def


p<-ggplot(vcf_f3_sp,aes(x=pop1_pop2,y=value,fill=pop_admix))+
  geom_bar(stat="identity", aes(color=def))+
  geom_errorbar(aes(ymin=value-se, ymax=value+se),width=.2,
                 position=position_dodge(.9)) +
  theme_bw() + 
  scale_fill_manual(values=color_med_atl$Col)+
  scale_color_manual(breaks=c("Negative","Zero"),values=c("chartreuse4","white"))+
  theme(
          panel.grid.major = element_blank(),
          panel.grid.minor = element_blank(),
          axis.text.x = element_text(angle=45)
  ) +
  scale_x_discrete(labels=c("Gulf of Lion;Costa Calida-Algarve" = "Costa Calida-Algarve",
                            "Gulf of Lion;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Gulf of Lion;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Costa Calida;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Costa Calida;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Costa Calida;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Algarve;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Algarve;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Algarve;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Bay of Biscay;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Bay of Biscay;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Bay of Biscay;Costa Calida-Algarve" = "Costa Calida-Algarve"))+
  xlab("Pop1,Pop2")+
  ylab("f3")
p<-ggplotly(p,height=500)  %>% partial_bundle() 
p
```




Lithognathus mormyrus {data-navmenu="Species"}
=======================================================================

Row {.tabset data-height=50}
-----------------------
  
<center>

<font size="6">**Lithognathus mormyrus**</font>

</center>

Row {.tabset data-height=2500}
-----------------------

### Filtered

```{r}
# Filtered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Lmorm" & !grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop_admix=as.character(vcf_f3_sp$pop_admix)
vcf_f3_sp$pop_1=as.character(vcf_f3_sp$pop_1)
vcf_f3_sp$pop_2=as.character(vcf_f3_sp$pop_2)

vcf_f3_sp[1:3,1]<-cell_spec(vcf_f3_sp[1:3,1], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[4:6,1]<-cell_spec(vcf_f3_sp[4:6,1], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[7:9,1]<-cell_spec(vcf_f3_sp[7:9,1], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[10:12,1]<-cell_spec(vcf_f3_sp[10:12,1], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3], color = color_med_atl$Col[4], bold = F)

kbl(vcf_f3_sp,col.names = c("Admixed population",
                           "Pop.1",
                           "Pop.2",
                           "f3",
                           "se",
                           "Z")
    ,escape = F,align=c(rep('c',times=6))) %>%
  kable_classic ("striped","hover", full_width = T,html_font = "Cambria") %>%
  row_spec(which(vcf_f3_sp$value<0 & vcf_f3_sp$Z<(-3)), bold = T, color = "black")
```


```{r}
# Filtered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Lmorm" & !grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop1_pop2=paste(vcf_f3_sp$pop_admix,";",vcf_f3_sp$pop_1,"-",vcf_f3_sp$pop_2,sep="")

vcf_f3_sp$pop1_pop2=factor(vcf_f3_sp$pop1_pop2,
                           levels=c(vcf_f3_sp$pop1_pop2))

def=c()
for (i in 1:nrow(vcf_f3_sp)){
  if (vcf_f3_sp$value[i]<0 & vcf_f3_sp$Z[i]<(-3)){
    def[i]="Negative"
  } else {
    def[i]="Zero"
  }
}
vcf_f3_sp$def=def


p<-ggplot(vcf_f3_sp,aes(x=pop1_pop2,y=value,fill=pop_admix))+
  geom_bar(stat="identity", aes(color=def))+
  geom_errorbar(aes(ymin=value-se, ymax=value+se),width=.2,
                 position=position_dodge(.9)) +
  theme_bw() + 
  scale_fill_manual(values=color_med_atl$Col)+
  scale_color_manual(breaks=c("Negative","Zero"),values=c("chartreuse4","white"))+
  theme(
          panel.grid.major = element_blank(),
          panel.grid.minor = element_blank(),
          axis.text.x = element_text(angle=45)
  ) +
  scale_x_discrete(labels=c("Gulf of Lion;Costa Calida-Algarve" = "Costa Calida-Algarve",
                            "Gulf of Lion;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Gulf of Lion;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Costa Calida;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Costa Calida;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Costa Calida;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Algarve;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Algarve;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Algarve;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Bay of Biscay;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Bay of Biscay;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Bay of Biscay;Costa Calida-Algarve" = "Costa Calida-Algarve"))+
  xlab("Pop1,Pop2")+
  ylab("f3")
p<-ggplotly(p,height=500)  %>% partial_bundle() 
p
```

### Unfiltered

```{r}
# Unfiltered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Lmorm" & grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop_admix=as.character(vcf_f3_sp$pop_admix)
vcf_f3_sp$pop_1=as.character(vcf_f3_sp$pop_1)
vcf_f3_sp$pop_2=as.character(vcf_f3_sp$pop_2)

vcf_f3_sp[1:3,1]<-cell_spec(vcf_f3_sp[1:3,1], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[4:6,1]<-cell_spec(vcf_f3_sp[4:6,1], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[7:9,1]<-cell_spec(vcf_f3_sp[7:9,1], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[10:12,1]<-cell_spec(vcf_f3_sp[10:12,1], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3], color = color_med_atl$Col[4], bold = F)

kbl(vcf_f3_sp,col.names = c("Admixed population",
                           "Pop.1",
                           "Pop.2",
                           "f3",
                           "se",
                           "Z")
    ,escape = F,align=c(rep('c',times=6))) %>%
  kable_classic ("striped","hover", full_width = T,html_font = "Cambria") %>%
  row_spec(which(vcf_f3_sp$value<0 & vcf_f3_sp$Z<(-3)), bold = T, color = "black")
```

```{r}
# Unfiltered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Lmorm" & grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop1_pop2=paste(vcf_f3_sp$pop_admix,";",vcf_f3_sp$pop_1,"-",vcf_f3_sp$pop_2,sep="")

vcf_f3_sp$pop1_pop2=factor(vcf_f3_sp$pop1_pop2,
                           levels=c(vcf_f3_sp$pop1_pop2))

def=c()
for (i in 1:nrow(vcf_f3_sp)){
  if (vcf_f3_sp$value[i]<0 & vcf_f3_sp$Z[i]<(-3)){
    def[i]="Negative"
  } else {
    def[i]="Zero"
  }
}
vcf_f3_sp$def=def


p<-ggplot(vcf_f3_sp,aes(x=pop1_pop2,y=value,fill=pop_admix))+
  geom_bar(stat="identity", aes(color=def))+
  geom_errorbar(aes(ymin=value-se, ymax=value+se),width=.2,
                 position=position_dodge(.9)) +
  theme_bw() + 
  scale_fill_manual(values=color_med_atl$Col)+
  scale_color_manual(breaks=c("Negative","Zero"),values=c("chartreuse4","white"))+
  theme(
          panel.grid.major = element_blank(),
          panel.grid.minor = element_blank(),
          axis.text.x = element_text(angle=45)
  ) +
  scale_x_discrete(labels=c("Gulf of Lion;Costa Calida-Algarve" = "Costa Calida-Algarve",
                            "Gulf of Lion;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Gulf of Lion;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Costa Calida;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Costa Calida;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Costa Calida;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Algarve;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Algarve;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Algarve;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Bay of Biscay;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Bay of Biscay;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Bay of Biscay;Costa Calida-Algarve" = "Costa Calida-Algarve"))+
  xlab("Pop1,Pop2")+
  ylab("f3")
p<-ggplotly(p,height=500)  %>% partial_bundle() 
p
```



Merluccius merluccius {data-navmenu="Species"}
=======================================================================

Row {.tabset data-height=50}
-----------------------
  
<center>

<font size="6">**Merluccius merluccius**</font>

</center>

Row {.tabset data-height=2500}
-----------------------

### Filtered

```{r}
# Filtered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Mmerl" & !grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop_admix=as.character(vcf_f3_sp$pop_admix)
vcf_f3_sp$pop_1=as.character(vcf_f3_sp$pop_1)
vcf_f3_sp$pop_2=as.character(vcf_f3_sp$pop_2)

vcf_f3_sp[1:3,1]<-cell_spec(vcf_f3_sp[1:3,1], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[4:6,1]<-cell_spec(vcf_f3_sp[4:6,1], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[7:9,1]<-cell_spec(vcf_f3_sp[7:9,1], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[10:12,1]<-cell_spec(vcf_f3_sp[10:12,1], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3], color = color_med_atl$Col[4], bold = F)

kbl(vcf_f3_sp,col.names = c("Admixed population",
                           "Pop.1",
                           "Pop.2",
                           "f3",
                           "se",
                           "Z")
    ,escape = F,align=c(rep('c',times=6))) %>%
  kable_classic ("striped","hover", full_width = T,html_font = "Cambria") %>%
  row_spec(which(vcf_f3_sp$value<0 & vcf_f3_sp$Z<(-3)), bold = T, color = "black")
```


```{r}
# Filtered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Mmerl" & !grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop1_pop2=paste(vcf_f3_sp$pop_admix,";",vcf_f3_sp$pop_1,"-",vcf_f3_sp$pop_2,sep="")

vcf_f3_sp$pop1_pop2=factor(vcf_f3_sp$pop1_pop2,
                           levels=c(vcf_f3_sp$pop1_pop2))

def=c()
for (i in 1:nrow(vcf_f3_sp)){
  if (vcf_f3_sp$value[i]<0 & vcf_f3_sp$Z[i]<(-3)){
    def[i]="Negative"
  } else {
    def[i]="Zero"
  }
}
vcf_f3_sp$def=def


p<-ggplot(vcf_f3_sp,aes(x=pop1_pop2,y=value,fill=pop_admix))+
  geom_bar(stat="identity", aes(color=def))+
  geom_errorbar(aes(ymin=value-se, ymax=value+se),width=.2,
                 position=position_dodge(.9)) +
  theme_bw() + 
  scale_fill_manual(values=color_med_atl$Col)+
  scale_color_manual(breaks=c("Negative","Zero"),values=c("chartreuse4","white"))+
  theme(
          panel.grid.major = element_blank(),
          panel.grid.minor = element_blank(),
          axis.text.x = element_text(angle=45)
  ) +
  scale_x_discrete(labels=c("Gulf of Lion;Costa Calida-Algarve" = "Costa Calida-Algarve",
                            "Gulf of Lion;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Gulf of Lion;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Costa Calida;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Costa Calida;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Costa Calida;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Algarve;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Algarve;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Algarve;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Bay of Biscay;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Bay of Biscay;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Bay of Biscay;Costa Calida-Algarve" = "Costa Calida-Algarve"))+
  xlab("Pop1,Pop2")+
  ylab("f3")
p<-ggplotly(p,height=500)  %>% partial_bundle() 
p
```

### Unfiltered

```{r}
# Unfiltered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Mmerl" & grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop_admix=as.character(vcf_f3_sp$pop_admix)
vcf_f3_sp$pop_1=as.character(vcf_f3_sp$pop_1)
vcf_f3_sp$pop_2=as.character(vcf_f3_sp$pop_2)

vcf_f3_sp[1:3,1]<-cell_spec(vcf_f3_sp[1:3,1], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[4:6,1]<-cell_spec(vcf_f3_sp[4:6,1], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[7:9,1]<-cell_spec(vcf_f3_sp[7:9,1], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[10:12,1]<-cell_spec(vcf_f3_sp[10:12,1], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3], color = color_med_atl$Col[4], bold = F)

kbl(vcf_f3_sp,col.names = c("Admixed population",
                           "Pop.1",
                           "Pop.2",
                           "f3",
                           "se",
                           "Z")
    ,escape = F,align=c(rep('c',times=6))) %>%
  kable_classic ("striped","hover", full_width = T,html_font = "Cambria") %>%
  row_spec(which(vcf_f3_sp$value<0 & vcf_f3_sp$Z<(-3)), bold = T, color = "black")
```

```{r}
# Unfiltered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Mmerl" & grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop1_pop2=paste(vcf_f3_sp$pop_admix,";",vcf_f3_sp$pop_1,"-",vcf_f3_sp$pop_2,sep="")

vcf_f3_sp$pop1_pop2=factor(vcf_f3_sp$pop1_pop2,
                           levels=c(vcf_f3_sp$pop1_pop2))

def=c()
for (i in 1:nrow(vcf_f3_sp)){
  if (vcf_f3_sp$value[i]<0 & vcf_f3_sp$Z[i]<(-3)){
    def[i]="Negative"
  } else {
    def[i]="Zero"
  }
}
vcf_f3_sp$def=def


p<-ggplot(vcf_f3_sp,aes(x=pop1_pop2,y=value,fill=pop_admix))+
  geom_bar(stat="identity", aes(color=def))+
  geom_errorbar(aes(ymin=value-se, ymax=value+se),width=.2,
                 position=position_dodge(.9)) +
  theme_bw() + 
  scale_fill_manual(values=color_med_atl$Col)+
  scale_color_manual(breaks=c("Negative","Zero"),values=c("chartreuse4","white"))+
  theme(
          panel.grid.major = element_blank(),
          panel.grid.minor = element_blank(),
          axis.text.x = element_text(angle=45)
  ) +
  scale_x_discrete(labels=c("Gulf of Lion;Costa Calida-Algarve" = "Costa Calida-Algarve",
                            "Gulf of Lion;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Gulf of Lion;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Costa Calida;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Costa Calida;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Costa Calida;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Algarve;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Algarve;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Algarve;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Bay of Biscay;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Bay of Biscay;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Bay of Biscay;Costa Calida-Algarve" = "Costa Calida-Algarve"))+
  xlab("Pop1,Pop2")+
  ylab("f3")
p<-ggplotly(p,height=500)  %>% partial_bundle() 
p
```

Mullus surmuletus {data-navmenu="Species"}
=======================================================================

Row {.tabset data-height=50}
-----------------------
  
<center>

<font size="6">**Mullus surmuletus**</font>

</center>

Row {.tabset data-height=2500}
-----------------------

### Filtered

```{r}
# Filtered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Msurm" & !grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop_admix=as.character(vcf_f3_sp$pop_admix)
vcf_f3_sp$pop_1=as.character(vcf_f3_sp$pop_1)
vcf_f3_sp$pop_2=as.character(vcf_f3_sp$pop_2)

vcf_f3_sp[1:3,1]<-cell_spec(vcf_f3_sp[1:3,1], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[4:6,1]<-cell_spec(vcf_f3_sp[4:6,1], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[7:9,1]<-cell_spec(vcf_f3_sp[7:9,1], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[10:12,1]<-cell_spec(vcf_f3_sp[10:12,1], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3], color = color_med_atl$Col[4], bold = F)

kbl(vcf_f3_sp,col.names = c("Admixed population",
                           "Pop.1",
                           "Pop.2",
                           "f3",
                           "se",
                           "Z")
    ,escape = F,align=c(rep('c',times=6))) %>%
  kable_classic ("striped","hover", full_width = T,html_font = "Cambria") %>%
  row_spec(which(vcf_f3_sp$value<0 & vcf_f3_sp$Z<(-3)), bold = T, color = "black")
```


```{r}
# Filtered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Msurm" & !grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop1_pop2=paste(vcf_f3_sp$pop_admix,";",vcf_f3_sp$pop_1,"-",vcf_f3_sp$pop_2,sep="")

vcf_f3_sp$pop1_pop2=factor(vcf_f3_sp$pop1_pop2,
                           levels=c(vcf_f3_sp$pop1_pop2))

def=c()
for (i in 1:nrow(vcf_f3_sp)){
  if (vcf_f3_sp$value[i]<0 & vcf_f3_sp$Z[i]<(-3)){
    def[i]="Negative"
  } else {
    def[i]="Zero"
  }
}
vcf_f3_sp$def=def


p<-ggplot(vcf_f3_sp,aes(x=pop1_pop2,y=value,fill=pop_admix))+
  geom_bar(stat="identity", aes(color=def))+
  geom_errorbar(aes(ymin=value-se, ymax=value+se),width=.2,
                 position=position_dodge(.9)) +
  theme_bw() + 
  scale_fill_manual(values=color_med_atl$Col)+
  scale_color_manual(breaks=c("Negative","Zero"),values=c("chartreuse4","white"))+
  theme(
          panel.grid.major = element_blank(),
          panel.grid.minor = element_blank(),
          axis.text.x = element_text(angle=45)
  ) +
  scale_x_discrete(labels=c("Gulf of Lion;Costa Calida-Algarve" = "Costa Calida-Algarve",
                            "Gulf of Lion;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Gulf of Lion;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Costa Calida;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Costa Calida;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Costa Calida;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Algarve;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Algarve;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Algarve;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Bay of Biscay;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Bay of Biscay;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Bay of Biscay;Costa Calida-Algarve" = "Costa Calida-Algarve"))+
  xlab("Pop1,Pop2")+
  ylab("f3")
p<-ggplotly(p,height=500)  %>% partial_bundle() 
p
```

### Unfiltered

```{r}
# Unfiltered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Msurm" & grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop_admix=as.character(vcf_f3_sp$pop_admix)
vcf_f3_sp$pop_1=as.character(vcf_f3_sp$pop_1)
vcf_f3_sp$pop_2=as.character(vcf_f3_sp$pop_2)

vcf_f3_sp[1:3,1]<-cell_spec(vcf_f3_sp[1:3,1], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[4:6,1]<-cell_spec(vcf_f3_sp[4:6,1], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[7:9,1]<-cell_spec(vcf_f3_sp[7:9,1], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[10:12,1]<-cell_spec(vcf_f3_sp[10:12,1], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3], color = color_med_atl$Col[4], bold = F)

kbl(vcf_f3_sp,col.names = c("Admixed population",
                           "Pop.1",
                           "Pop.2",
                           "f3",
                           "se",
                           "Z")
    ,escape = F,align=c(rep('c',times=6))) %>%
  kable_classic ("striped","hover", full_width = T,html_font = "Cambria") %>%
  row_spec(which(vcf_f3_sp$value<0 & vcf_f3_sp$Z<(-3)), bold = T, color = "black")
```

```{r}
# Unfiltered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Msurm" & grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop1_pop2=paste(vcf_f3_sp$pop_admix,";",vcf_f3_sp$pop_1,"-",vcf_f3_sp$pop_2,sep="")

vcf_f3_sp$pop1_pop2=factor(vcf_f3_sp$pop1_pop2,
                           levels=c(vcf_f3_sp$pop1_pop2))

def=c()
for (i in 1:nrow(vcf_f3_sp)){
  if (vcf_f3_sp$value[i]<0 & vcf_f3_sp$Z[i]<(-3)){
    def[i]="Negative"
  } else {
    def[i]="Zero"
  }
}
vcf_f3_sp$def=def


p<-ggplot(vcf_f3_sp,aes(x=pop1_pop2,y=value,fill=pop_admix))+
  geom_bar(stat="identity", aes(color=def))+
  geom_errorbar(aes(ymin=value-se, ymax=value+se),width=.2,
                 position=position_dodge(.9)) +
  theme_bw() + 
  scale_fill_manual(values=color_med_atl$Col)+
  scale_color_manual(breaks=c("Negative","Zero"),values=c("chartreuse4","white"))+
  theme(
          panel.grid.major = element_blank(),
          panel.grid.minor = element_blank(),
          axis.text.x = element_text(angle=45)
  ) +
  scale_x_discrete(labels=c("Gulf of Lion;Costa Calida-Algarve" = "Costa Calida-Algarve",
                            "Gulf of Lion;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Gulf of Lion;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Costa Calida;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Costa Calida;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Costa Calida;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Algarve;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Algarve;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Algarve;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Bay of Biscay;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Bay of Biscay;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Bay of Biscay;Costa Calida-Algarve" = "Costa Calida-Algarve"))+
  xlab("Pop1,Pop2")+
  ylab("f3")
p<-ggplotly(p,height=500)  %>% partial_bundle() 
p
```

Pagellus erythrinus {data-navmenu="Species"}
=======================================================================

Row {.tabset data-height=50}
-----------------------
  
<center>

<font size="6">**Pagellus erythrinus**</font>

</center>

Row {.tabset data-height=2500}
-----------------------

### Filtered

```{r}
# Filtered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Peryt" & !grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop_admix=as.character(vcf_f3_sp$pop_admix)
vcf_f3_sp$pop_1=as.character(vcf_f3_sp$pop_1)
vcf_f3_sp$pop_2=as.character(vcf_f3_sp$pop_2)

vcf_f3_sp[1:3,1]<-cell_spec(vcf_f3_sp[1:3,1], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[4:6,1]<-cell_spec(vcf_f3_sp[4:6,1], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[7:9,1]<-cell_spec(vcf_f3_sp[7:9,1], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[10:12,1]<-cell_spec(vcf_f3_sp[10:12,1], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3], color = color_med_atl$Col[4], bold = F)

kbl(vcf_f3_sp,col.names = c("Admixed population",
                           "Pop.1",
                           "Pop.2",
                           "f3",
                           "se",
                           "Z")
    ,escape = F,align=c(rep('c',times=6))) %>%
  kable_classic ("striped","hover", full_width = T,html_font = "Cambria") %>%
  row_spec(which(vcf_f3_sp$value<0 & vcf_f3_sp$Z<(-3)), bold = T, color = "black")
```


```{r}
# Filtered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Peryt" & !grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop1_pop2=paste(vcf_f3_sp$pop_admix,";",vcf_f3_sp$pop_1,"-",vcf_f3_sp$pop_2,sep="")

vcf_f3_sp$pop1_pop2=factor(vcf_f3_sp$pop1_pop2,
                           levels=c(vcf_f3_sp$pop1_pop2))

def=c()
for (i in 1:nrow(vcf_f3_sp)){
  if (vcf_f3_sp$value[i]<0 & vcf_f3_sp$Z[i]<(-3)){
    def[i]="Negative"
  } else {
    def[i]="Zero"
  }
}
vcf_f3_sp$def=def


p<-ggplot(vcf_f3_sp,aes(x=pop1_pop2,y=value,fill=pop_admix))+
  geom_bar(stat="identity", aes(color=def))+
  geom_errorbar(aes(ymin=value-se, ymax=value+se),width=.2,
                 position=position_dodge(.9)) +
  theme_bw() + 
  scale_fill_manual(values=color_med_atl$Col)+
  scale_color_manual(breaks=c("Negative","Zero"),values=c("chartreuse4","white"))+
  theme(
          panel.grid.major = element_blank(),
          panel.grid.minor = element_blank(),
          axis.text.x = element_text(angle=45)
  ) +
  scale_x_discrete(labels=c("Gulf of Lion;Costa Calida-Algarve" = "Costa Calida-Algarve",
                            "Gulf of Lion;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Gulf of Lion;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Costa Calida;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Costa Calida;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Costa Calida;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Algarve;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Algarve;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Algarve;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Bay of Biscay;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Bay of Biscay;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Bay of Biscay;Costa Calida-Algarve" = "Costa Calida-Algarve"))+
  xlab("Pop1,Pop2")+
  ylab("f3")
p<-ggplotly(p,height=500)  %>% partial_bundle() 
p
```

### Unfiltered

```{r}
# Unfiltered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Peryt" & grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop_admix=as.character(vcf_f3_sp$pop_admix)
vcf_f3_sp$pop_1=as.character(vcf_f3_sp$pop_1)
vcf_f3_sp$pop_2=as.character(vcf_f3_sp$pop_2)

vcf_f3_sp[1:3,1]<-cell_spec(vcf_f3_sp[1:3,1], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[4:6,1]<-cell_spec(vcf_f3_sp[4:6,1], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[7:9,1]<-cell_spec(vcf_f3_sp[7:9,1], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[10:12,1]<-cell_spec(vcf_f3_sp[10:12,1], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3], color = color_med_atl$Col[4], bold = F)

kbl(vcf_f3_sp,col.names = c("Admixed population",
                           "Pop.1",
                           "Pop.2",
                           "f3",
                           "se",
                           "Z")
    ,escape = F,align=c(rep('c',times=6))) %>%
  kable_classic ("striped","hover", full_width = T,html_font = "Cambria") %>%
  row_spec(which(vcf_f3_sp$value<0 & vcf_f3_sp$Z<(-3)), bold = T, color = "black")
```

```{r}
# Unfiltered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Peryt" & grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop1_pop2=paste(vcf_f3_sp$pop_admix,";",vcf_f3_sp$pop_1,"-",vcf_f3_sp$pop_2,sep="")

vcf_f3_sp$pop1_pop2=factor(vcf_f3_sp$pop1_pop2,
                           levels=c(vcf_f3_sp$pop1_pop2))

def=c()
for (i in 1:nrow(vcf_f3_sp)){
  if (vcf_f3_sp$value[i]<0 & vcf_f3_sp$Z[i]<(-3)){
    def[i]="Negative"
  } else {
    def[i]="Zero"
  }
}
vcf_f3_sp$def=def


p<-ggplot(vcf_f3_sp,aes(x=pop1_pop2,y=value,fill=pop_admix))+
  geom_bar(stat="identity", aes(color=def))+
  geom_errorbar(aes(ymin=value-se, ymax=value+se),width=.2,
                 position=position_dodge(.9)) +
  theme_bw() + 
  scale_fill_manual(values=color_med_atl$Col)+
  scale_color_manual(breaks=c("Negative","Zero"),values=c("chartreuse4","white"))+
  theme(
          panel.grid.major = element_blank(),
          panel.grid.minor = element_blank(),
          axis.text.x = element_text(angle=45)
  ) +
  scale_x_discrete(labels=c("Gulf of Lion;Costa Calida-Algarve" = "Costa Calida-Algarve",
                            "Gulf of Lion;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Gulf of Lion;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Costa Calida;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Costa Calida;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Costa Calida;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Algarve;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Algarve;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Algarve;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Bay of Biscay;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Bay of Biscay;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Bay of Biscay;Costa Calida-Algarve" = "Costa Calida-Algarve"))+
  xlab("Pop1,Pop2")+
  ylab("f3")
p<-ggplotly(p,height=500)  %>% partial_bundle() 
p
```

Serranus cabrilla {data-navmenu="Species"}
=======================================================================

Row {.tabset data-height=50}
-----------------------
  
<center>

<font size="6">**Serranus cabrilla**</font>

</center>

Row {.tabset data-height=2500}
-----------------------

### Filtered

```{r}
# Filtered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Scabr" & !grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop_admix=as.character(vcf_f3_sp$pop_admix)
vcf_f3_sp$pop_1=as.character(vcf_f3_sp$pop_1)
vcf_f3_sp$pop_2=as.character(vcf_f3_sp$pop_2)

vcf_f3_sp[1:3,1]<-cell_spec(vcf_f3_sp[1:3,1], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[4:6,1]<-cell_spec(vcf_f3_sp[4:6,1], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[7:9,1]<-cell_spec(vcf_f3_sp[7:9,1], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[10:12,1]<-cell_spec(vcf_f3_sp[10:12,1], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3], color = color_med_atl$Col[4], bold = F)

kbl(vcf_f3_sp,col.names = c("Admixed population",
                           "Pop.1",
                           "Pop.2",
                           "f3",
                           "se",
                           "Z")
    ,escape = F,align=c(rep('c',times=6))) %>%
  kable_classic ("striped","hover", full_width = T,html_font = "Cambria") %>%
  row_spec(which(vcf_f3_sp$value<0 & vcf_f3_sp$Z<(-3)), bold = T, color = "black")
```


```{r}
# Filtered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Scabr" & !grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop1_pop2=paste(vcf_f3_sp$pop_admix,";",vcf_f3_sp$pop_1,"-",vcf_f3_sp$pop_2,sep="")

vcf_f3_sp$pop1_pop2=factor(vcf_f3_sp$pop1_pop2,
                           levels=c(vcf_f3_sp$pop1_pop2))

def=c()
for (i in 1:nrow(vcf_f3_sp)){
  if (vcf_f3_sp$value[i]<0 & vcf_f3_sp$Z[i]<(-3)){
    def[i]="Negative"
  } else {
    def[i]="Zero"
  }
}
vcf_f3_sp$def=def


p<-ggplot(vcf_f3_sp,aes(x=pop1_pop2,y=value,fill=pop_admix))+
  geom_bar(stat="identity", aes(color=def))+
  geom_errorbar(aes(ymin=value-se, ymax=value+se),width=.2,
                 position=position_dodge(.9)) +
  theme_bw() + 
  scale_fill_manual(values=color_med_atl$Col)+
  scale_color_manual(breaks=c("Negative","Zero"),values=c("chartreuse4","white"))+
  theme(
          panel.grid.major = element_blank(),
          panel.grid.minor = element_blank(),
          axis.text.x = element_text(angle=45)
  ) +
  scale_x_discrete(labels=c("Gulf of Lion;Costa Calida-Algarve" = "Costa Calida-Algarve",
                            "Gulf of Lion;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Gulf of Lion;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Costa Calida;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Costa Calida;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Costa Calida;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Algarve;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Algarve;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Algarve;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Bay of Biscay;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Bay of Biscay;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Bay of Biscay;Costa Calida-Algarve" = "Costa Calida-Algarve"))+
  xlab("Pop1,Pop2")+
  ylab("f3")
p<-ggplotly(p,height=500)  %>% partial_bundle() 
p
```

### Unfiltered

```{r}
# Unfiltered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Scabr" & grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop_admix=as.character(vcf_f3_sp$pop_admix)
vcf_f3_sp$pop_1=as.character(vcf_f3_sp$pop_1)
vcf_f3_sp$pop_2=as.character(vcf_f3_sp$pop_2)

vcf_f3_sp[1:3,1]<-cell_spec(vcf_f3_sp[1:3,1], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[4:6,1]<-cell_spec(vcf_f3_sp[4:6,1], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[7:9,1]<-cell_spec(vcf_f3_sp[7:9,1], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[10:12,1]<-cell_spec(vcf_f3_sp[10:12,1], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3], color = color_med_atl$Col[4], bold = F)

kbl(vcf_f3_sp,col.names = c("Admixed population",
                           "Pop.1",
                           "Pop.2",
                           "f3",
                           "se",
                           "Z")
    ,escape = F,align=c(rep('c',times=6))) %>%
  kable_classic ("striped","hover", full_width = T,html_font = "Cambria") %>%
  row_spec(which(vcf_f3_sp$value<0 & vcf_f3_sp$Z<(-3)), bold = T, color = "black")
```

```{r}
# Unfiltered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Scabr" & grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop1_pop2=paste(vcf_f3_sp$pop_admix,";",vcf_f3_sp$pop_1,"-",vcf_f3_sp$pop_2,sep="")

vcf_f3_sp$pop1_pop2=factor(vcf_f3_sp$pop1_pop2,
                           levels=c(vcf_f3_sp$pop1_pop2))

def=c()
for (i in 1:nrow(vcf_f3_sp)){
  if (vcf_f3_sp$value[i]<0 & vcf_f3_sp$Z[i]<(-3)){
    def[i]="Negative"
  } else {
    def[i]="Zero"
  }
}
vcf_f3_sp$def=def


p<-ggplot(vcf_f3_sp,aes(x=pop1_pop2,y=value,fill=pop_admix))+
  geom_bar(stat="identity", aes(color=def))+
  geom_errorbar(aes(ymin=value-se, ymax=value+se),width=.2,
                 position=position_dodge(.9)) +
  theme_bw() + 
  scale_fill_manual(values=color_med_atl$Col)+
  scale_color_manual(breaks=c("Negative","Zero"),values=c("chartreuse4","white"))+
  theme(
          panel.grid.major = element_blank(),
          panel.grid.minor = element_blank(),
          axis.text.x = element_text(angle=45)
  ) +
  scale_x_discrete(labels=c("Gulf of Lion;Costa Calida-Algarve" = "Costa Calida-Algarve",
                            "Gulf of Lion;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Gulf of Lion;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Costa Calida;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Costa Calida;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Costa Calida;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Algarve;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Algarve;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Algarve;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Bay of Biscay;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Bay of Biscay;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Bay of Biscay;Costa Calida-Algarve" = "Costa Calida-Algarve"))+
  xlab("Pop1,Pop2")+
  ylab("f3")
p<-ggplotly(p,height=500)  %>% partial_bundle() 
p
```

Spondyliosoma cantharus {data-navmenu="Species"}
=======================================================================

Row {.tabset data-height=50}
-----------------------
  
<center>

<font size="6">**Spondyliosoma cantharus**</font>

</center>

Row {.tabset data-height=2500}
-----------------------

### Filtered

```{r}
# Filtered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Scant" & !grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop_admix=as.character(vcf_f3_sp$pop_admix)
vcf_f3_sp$pop_1=as.character(vcf_f3_sp$pop_1)
vcf_f3_sp$pop_2=as.character(vcf_f3_sp$pop_2)

vcf_f3_sp[1:3,1]<-cell_spec(vcf_f3_sp[1:3,1], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[4:6,1]<-cell_spec(vcf_f3_sp[4:6,1], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[7:9,1]<-cell_spec(vcf_f3_sp[7:9,1], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[10:12,1]<-cell_spec(vcf_f3_sp[10:12,1], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3], color = color_med_atl$Col[4], bold = F)

kbl(vcf_f3_sp,col.names = c("Admixed population",
                           "Pop.1",
                           "Pop.2",
                           "f3",
                           "se",
                           "Z")
    ,escape = F,align=c(rep('c',times=6))) %>%
  kable_classic ("striped","hover", full_width = T,html_font = "Cambria") %>%
  row_spec(which(vcf_f3_sp$value<0 & vcf_f3_sp$Z<(-3)), bold = T, color = "black")
```


```{r}
# Filtered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Scant" & !grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop1_pop2=paste(vcf_f3_sp$pop_admix,";",vcf_f3_sp$pop_1,"-",vcf_f3_sp$pop_2,sep="")

vcf_f3_sp$pop1_pop2=factor(vcf_f3_sp$pop1_pop2,
                           levels=c(vcf_f3_sp$pop1_pop2))

def=c()
for (i in 1:nrow(vcf_f3_sp)){
  if (vcf_f3_sp$value[i]<0 & vcf_f3_sp$Z[i]<(-3)){
    def[i]="Negative"
  } else {
    def[i]="Zero"
  }
}
vcf_f3_sp$def=def


p<-ggplot(vcf_f3_sp,aes(x=pop1_pop2,y=value,fill=pop_admix))+
  geom_bar(stat="identity", aes(color=def))+
  geom_errorbar(aes(ymin=value-se, ymax=value+se),width=.2,
                 position=position_dodge(.9)) +
  theme_bw() + 
  scale_fill_manual(values=color_med_atl$Col)+
  scale_color_manual(breaks=c("Negative","Zero"),values=c("chartreuse4","white"))+
  theme(
          panel.grid.major = element_blank(),
          panel.grid.minor = element_blank(),
          axis.text.x = element_text(angle=45)
  ) +
  scale_x_discrete(labels=c("Gulf of Lion;Costa Calida-Algarve" = "Costa Calida-Algarve",
                            "Gulf of Lion;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Gulf of Lion;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Costa Calida;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Costa Calida;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Costa Calida;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Algarve;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Algarve;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Algarve;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Bay of Biscay;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Bay of Biscay;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Bay of Biscay;Costa Calida-Algarve" = "Costa Calida-Algarve"))+
  xlab("Pop1,Pop2")+
  ylab("f3")
p<-ggplotly(p,height=500)  %>% partial_bundle() 
p
```

### Unfiltered

```{r}
# Unfiltered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Scant" & grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop_admix=as.character(vcf_f3_sp$pop_admix)
vcf_f3_sp$pop_1=as.character(vcf_f3_sp$pop_1)
vcf_f3_sp$pop_2=as.character(vcf_f3_sp$pop_2)

vcf_f3_sp[1:3,1]<-cell_spec(vcf_f3_sp[1:3,1], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[4:6,1]<-cell_spec(vcf_f3_sp[4:6,1], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[7:9,1]<-cell_spec(vcf_f3_sp[7:9,1], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[10:12,1]<-cell_spec(vcf_f3_sp[10:12,1], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3], color = color_med_atl$Col[4], bold = F)

kbl(vcf_f3_sp,col.names = c("Admixed population",
                           "Pop.1",
                           "Pop.2",
                           "f3",
                           "se",
                           "Z")
    ,escape = F,align=c(rep('c',times=6))) %>%
  kable_classic ("striped","hover", full_width = T,html_font = "Cambria") %>%
  row_spec(which(vcf_f3_sp$value<0 & vcf_f3_sp$Z<(-3)), bold = T, color = "black")
```

```{r}
# Unfiltered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Scant" & grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop1_pop2=paste(vcf_f3_sp$pop_admix,";",vcf_f3_sp$pop_1,"-",vcf_f3_sp$pop_2,sep="")

vcf_f3_sp$pop1_pop2=factor(vcf_f3_sp$pop1_pop2,
                           levels=c(vcf_f3_sp$pop1_pop2))

def=c()
for (i in 1:nrow(vcf_f3_sp)){
  if (vcf_f3_sp$value[i]<0 & vcf_f3_sp$Z[i]<(-3)){
    def[i]="Negative"
  } else {
    def[i]="Zero"
  }
}
vcf_f3_sp$def=def


p<-ggplot(vcf_f3_sp,aes(x=pop1_pop2,y=value,fill=pop_admix))+
  geom_bar(stat="identity", aes(color=def))+
  geom_errorbar(aes(ymin=value-se, ymax=value+se),width=.2,
                 position=position_dodge(.9)) +
  theme_bw() + 
  scale_fill_manual(values=color_med_atl$Col)+
  scale_color_manual(breaks=c("Negative","Zero"),values=c("chartreuse4","white"))+
  theme(
          panel.grid.major = element_blank(),
          panel.grid.minor = element_blank(),
          axis.text.x = element_text(angle=45)
  ) +
  scale_x_discrete(labels=c("Gulf of Lion;Costa Calida-Algarve" = "Costa Calida-Algarve",
                            "Gulf of Lion;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Gulf of Lion;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Costa Calida;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Costa Calida;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Costa Calida;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Algarve;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Algarve;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Algarve;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Bay of Biscay;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Bay of Biscay;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Bay of Biscay;Costa Calida-Algarve" = "Costa Calida-Algarve"))+
  xlab("Pop1,Pop2")+
  ylab("f3")
p<-ggplotly(p,height=500)  %>% partial_bundle() 
p
```

Symphodus cinereus {data-navmenu="Species"}
=======================================================================

Row {.tabset data-height=50}
-----------------------
  
<center>

<font size="6">**Symphodus cinereus**</font>

</center>

Row {.tabset data-height=2500}
-----------------------

### Filtered

```{r}
# Filtered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Scine" & !grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop_admix=as.character(vcf_f3_sp$pop_admix)
vcf_f3_sp$pop_1=as.character(vcf_f3_sp$pop_1)
vcf_f3_sp$pop_2=as.character(vcf_f3_sp$pop_2)

vcf_f3_sp[1:3,1]<-cell_spec(vcf_f3_sp[1:3,1], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[4:6,1]<-cell_spec(vcf_f3_sp[4:6,1], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[7:9,1]<-cell_spec(vcf_f3_sp[7:9,1], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[10:12,1]<-cell_spec(vcf_f3_sp[10:12,1], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3], color = color_med_atl$Col[4], bold = F)

kbl(vcf_f3_sp,col.names = c("Admixed population",
                           "Pop.1",
                           "Pop.2",
                           "f3",
                           "se",
                           "Z")
    ,escape = F,align=c(rep('c',times=6))) %>%
  kable_classic ("striped","hover", full_width = T,html_font = "Cambria") %>%
  row_spec(which(vcf_f3_sp$value<0 & vcf_f3_sp$Z<(-3)), bold = T, color = "black")
```


```{r}
# Filtered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Scine" & !grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop1_pop2=paste(vcf_f3_sp$pop_admix,";",vcf_f3_sp$pop_1,"-",vcf_f3_sp$pop_2,sep="")

vcf_f3_sp$pop1_pop2=factor(vcf_f3_sp$pop1_pop2,
                           levels=c(vcf_f3_sp$pop1_pop2))

def=c()
for (i in 1:nrow(vcf_f3_sp)){
  if (vcf_f3_sp$value[i]<0 & vcf_f3_sp$Z[i]<(-3)){
    def[i]="Negative"
  } else {
    def[i]="Zero"
  }
}
vcf_f3_sp$def=def


p<-ggplot(vcf_f3_sp,aes(x=pop1_pop2,y=value,fill=pop_admix))+
  geom_bar(stat="identity", aes(color=def))+
  geom_errorbar(aes(ymin=value-se, ymax=value+se),width=.2,
                 position=position_dodge(.9)) +
  theme_bw() + 
  scale_fill_manual(values=color_med_atl$Col)+
  scale_color_manual(breaks=c("Negative","Zero"),values=c("chartreuse4","white"))+
  theme(
          panel.grid.major = element_blank(),
          panel.grid.minor = element_blank(),
          axis.text.x = element_text(angle=45)
  ) +
  scale_x_discrete(labels=c("Gulf of Lion;Costa Calida-Algarve" = "Costa Calida-Algarve",
                            "Gulf of Lion;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Gulf of Lion;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Costa Calida;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Costa Calida;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Costa Calida;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Algarve;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Algarve;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Algarve;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Bay of Biscay;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Bay of Biscay;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Bay of Biscay;Costa Calida-Algarve" = "Costa Calida-Algarve"))+
  xlab("Pop1,Pop2")+
  ylab("f3")
p<-ggplotly(p,height=500)  %>% partial_bundle() 
p
```

### Unfiltered

```{r}
# Unfiltered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Scine" & grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop_admix=as.character(vcf_f3_sp$pop_admix)
vcf_f3_sp$pop_1=as.character(vcf_f3_sp$pop_1)
vcf_f3_sp$pop_2=as.character(vcf_f3_sp$pop_2)

vcf_f3_sp[1:3,1]<-cell_spec(vcf_f3_sp[1:3,1], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[4:6,1]<-cell_spec(vcf_f3_sp[4:6,1], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[7:9,1]<-cell_spec(vcf_f3_sp[7:9,1], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[10:12,1]<-cell_spec(vcf_f3_sp[10:12,1], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3], color = color_med_atl$Col[4], bold = F)

kbl(vcf_f3_sp,col.names = c("Admixed population",
                           "Pop.1",
                           "Pop.2",
                           "f3",
                           "se",
                           "Z")
    ,escape = F,align=c(rep('c',times=6))) %>%
  kable_classic ("striped","hover", full_width = T,html_font = "Cambria") %>%
  row_spec(which(vcf_f3_sp$value<0 & vcf_f3_sp$Z<(-3)), bold = T, color = "black")
```

```{r}
# Unfiltered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Scine" & grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop1_pop2=paste(vcf_f3_sp$pop_admix,";",vcf_f3_sp$pop_1,"-",vcf_f3_sp$pop_2,sep="")

vcf_f3_sp$pop1_pop2=factor(vcf_f3_sp$pop1_pop2,
                           levels=c(vcf_f3_sp$pop1_pop2))

def=c()
for (i in 1:nrow(vcf_f3_sp)){
  if (vcf_f3_sp$value[i]<0 & vcf_f3_sp$Z[i]<(-3)){
    def[i]="Negative"
  } else {
    def[i]="Zero"
  }
}
vcf_f3_sp$def=def


p<-ggplot(vcf_f3_sp,aes(x=pop1_pop2,y=value,fill=pop_admix))+
  geom_bar(stat="identity", aes(color=def))+
  geom_errorbar(aes(ymin=value-se, ymax=value+se),width=.2,
                 position=position_dodge(.9)) +
  theme_bw() + 
  scale_fill_manual(values=color_med_atl$Col)+
  scale_color_manual(breaks=c("Negative","Zero"),values=c("chartreuse4","white"))+
  theme(
          panel.grid.major = element_blank(),
          panel.grid.minor = element_blank(),
          axis.text.x = element_text(angle=45)
  ) +
  scale_x_discrete(labels=c("Gulf of Lion;Costa Calida-Algarve" = "Costa Calida-Algarve",
                            "Gulf of Lion;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Gulf of Lion;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Costa Calida;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Costa Calida;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Costa Calida;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Algarve;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Algarve;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Algarve;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Bay of Biscay;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Bay of Biscay;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Bay of Biscay;Costa Calida-Algarve" = "Costa Calida-Algarve"))+
  xlab("Pop1,Pop2")+
  ylab("f3")
p<-ggplotly(p,height=500)  %>% partial_bundle() 
p
```

Sardina pilchardus {data-navmenu="Species"}
=======================================================================

Row {.tabset data-height=50}
-----------------------
  
<center>

<font size="6">**Sardina pilchardus**</font>

</center>

Row {.tabset data-height=2500}
-----------------------

### Filtered

```{r}
# Filtered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Spilc" & !grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop_admix=as.character(vcf_f3_sp$pop_admix)
vcf_f3_sp$pop_1=as.character(vcf_f3_sp$pop_1)
vcf_f3_sp$pop_2=as.character(vcf_f3_sp$pop_2)

vcf_f3_sp[1:3,1]<-cell_spec(vcf_f3_sp[1:3,1], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[4:6,1]<-cell_spec(vcf_f3_sp[4:6,1], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[7:9,1]<-cell_spec(vcf_f3_sp[7:9,1], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[10:12,1]<-cell_spec(vcf_f3_sp[10:12,1], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3], color = color_med_atl$Col[4], bold = F)

kbl(vcf_f3_sp,col.names = c("Admixed population",
                           "Pop.1",
                           "Pop.2",
                           "f3",
                           "se",
                           "Z")
    ,escape = F,align=c(rep('c',times=6))) %>%
  kable_classic ("striped","hover", full_width = T,html_font = "Cambria") %>%
  row_spec(which(vcf_f3_sp$value<0 & vcf_f3_sp$Z<(-3)), bold = T, color = "black")
```


```{r}
# Filtered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Spilc" & !grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop1_pop2=paste(vcf_f3_sp$pop_admix,";",vcf_f3_sp$pop_1,"-",vcf_f3_sp$pop_2,sep="")

vcf_f3_sp$pop1_pop2=factor(vcf_f3_sp$pop1_pop2,
                           levels=c(vcf_f3_sp$pop1_pop2))

def=c()
for (i in 1:nrow(vcf_f3_sp)){
  if (vcf_f3_sp$value[i]<0 & vcf_f3_sp$Z[i]<(-3)){
    def[i]="Negative"
  } else {
    def[i]="Zero"
  }
}
vcf_f3_sp$def=def


p<-ggplot(vcf_f3_sp,aes(x=pop1_pop2,y=value,fill=pop_admix))+
  geom_bar(stat="identity", aes(color=def))+
  geom_errorbar(aes(ymin=value-se, ymax=value+se),width=.2,
                 position=position_dodge(.9)) +
  theme_bw() + 
  scale_fill_manual(values=color_med_atl$Col)+
  scale_color_manual(breaks=c("Negative","Zero"),values=c("chartreuse4","white"))+
  theme(
          panel.grid.major = element_blank(),
          panel.grid.minor = element_blank(),
          axis.text.x = element_text(angle=45)
  ) +
  scale_x_discrete(labels=c("Gulf of Lion;Costa Calida-Algarve" = "Costa Calida-Algarve",
                            "Gulf of Lion;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Gulf of Lion;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Costa Calida;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Costa Calida;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Costa Calida;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Algarve;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Algarve;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Algarve;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Bay of Biscay;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Bay of Biscay;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Bay of Biscay;Costa Calida-Algarve" = "Costa Calida-Algarve"))+
  xlab("Pop1,Pop2")+
  ylab("f3")
p<-ggplotly(p,height=500)  %>% partial_bundle() 
p
```

### Unfiltered

```{r}
# Unfiltered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Spilc" & grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop_admix=as.character(vcf_f3_sp$pop_admix)
vcf_f3_sp$pop_1=as.character(vcf_f3_sp$pop_1)
vcf_f3_sp$pop_2=as.character(vcf_f3_sp$pop_2)

vcf_f3_sp[1:3,1]<-cell_spec(vcf_f3_sp[1:3,1], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[4:6,1]<-cell_spec(vcf_f3_sp[4:6,1], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[7:9,1]<-cell_spec(vcf_f3_sp[7:9,1], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[10:12,1]<-cell_spec(vcf_f3_sp[10:12,1], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3], color = color_med_atl$Col[4], bold = F)

kbl(vcf_f3_sp,col.names = c("Admixed population",
                           "Pop.1",
                           "Pop.2",
                           "f3",
                           "se",
                           "Z")
    ,escape = F,align=c(rep('c',times=6))) %>%
  kable_classic ("striped","hover", full_width = T,html_font = "Cambria") %>%
  row_spec(which(vcf_f3_sp$value<0 & vcf_f3_sp$Z<(-3)), bold = T, color = "black")
```

```{r}
# Unfiltered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Spilc" & grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop1_pop2=paste(vcf_f3_sp$pop_admix,";",vcf_f3_sp$pop_1,"-",vcf_f3_sp$pop_2,sep="")

vcf_f3_sp$pop1_pop2=factor(vcf_f3_sp$pop1_pop2,
                           levels=c(vcf_f3_sp$pop1_pop2))

def=c()
for (i in 1:nrow(vcf_f3_sp)){
  if (vcf_f3_sp$value[i]<0 & vcf_f3_sp$Z[i]<(-3)){
    def[i]="Negative"
  } else {
    def[i]="Zero"
  }
}
vcf_f3_sp$def=def


p<-ggplot(vcf_f3_sp,aes(x=pop1_pop2,y=value,fill=pop_admix))+
  geom_bar(stat="identity", aes(color=def))+
  geom_errorbar(aes(ymin=value-se, ymax=value+se),width=.2,
                 position=position_dodge(.9)) +
  theme_bw() + 
  scale_fill_manual(values=color_med_atl$Col)+
  scale_color_manual(breaks=c("Negative","Zero"),values=c("chartreuse4","white"))+
  theme(
          panel.grid.major = element_blank(),
          panel.grid.minor = element_blank(),
          axis.text.x = element_text(angle=45)
  ) +
  scale_x_discrete(labels=c("Gulf of Lion;Costa Calida-Algarve" = "Costa Calida-Algarve",
                            "Gulf of Lion;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Gulf of Lion;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Costa Calida;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Costa Calida;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Costa Calida;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Algarve;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Algarve;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Algarve;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Bay of Biscay;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Bay of Biscay;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Bay of Biscay;Costa Calida-Algarve" = "Costa Calida-Algarve"))+
  xlab("Pop1,Pop2")+
  ylab("f3")
p<-ggplotly(p,height=500)  %>% partial_bundle() 
p
```

Sarda sarda {data-navmenu="Species"}
=======================================================================

Row {.tabset data-height=50}
-----------------------
  
<center>

<font size="6">**Sarda sarda**</font>

</center>

Row {.tabset data-height=2500}
-----------------------

### Filtered

```{r}
# Filtered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Ssard" & !grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop_admix=as.character(vcf_f3_sp$pop_admix)
vcf_f3_sp$pop_1=as.character(vcf_f3_sp$pop_1)
vcf_f3_sp$pop_2=as.character(vcf_f3_sp$pop_2)

vcf_f3_sp[1:3,1]<-cell_spec(vcf_f3_sp[1:3,1], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[4:6,1]<-cell_spec(vcf_f3_sp[4:6,1], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[7:9,1]<-cell_spec(vcf_f3_sp[7:9,1], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[10:12,1]<-cell_spec(vcf_f3_sp[10:12,1], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3], color = color_med_atl$Col[4], bold = F)

kbl(vcf_f3_sp,col.names = c("Admixed population",
                           "Pop.1",
                           "Pop.2",
                           "f3",
                           "se",
                           "Z")
    ,escape = F,align=c(rep('c',times=6))) %>%
  kable_classic ("striped","hover", full_width = T,html_font = "Cambria") %>%
  row_spec(which(vcf_f3_sp$value<0 & vcf_f3_sp$Z<(-3)), bold = T, color = "black")
```


```{r}
# Filtered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Ssard" & !grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop1_pop2=paste(vcf_f3_sp$pop_admix,";",vcf_f3_sp$pop_1,"-",vcf_f3_sp$pop_2,sep="")

vcf_f3_sp$pop1_pop2=factor(vcf_f3_sp$pop1_pop2,
                           levels=c(vcf_f3_sp$pop1_pop2))

def=c()
for (i in 1:nrow(vcf_f3_sp)){
  if (vcf_f3_sp$value[i]<0 & vcf_f3_sp$Z[i]<(-3)){
    def[i]="Negative"
  } else {
    def[i]="Zero"
  }
}
vcf_f3_sp$def=def


p<-ggplot(vcf_f3_sp,aes(x=pop1_pop2,y=value,fill=pop_admix))+
  geom_bar(stat="identity", aes(color=def))+
  geom_errorbar(aes(ymin=value-se, ymax=value+se),width=.2,
                 position=position_dodge(.9)) +
  theme_bw() + 
  scale_fill_manual(values=color_med_atl$Col)+
  scale_color_manual(breaks=c("Negative","Zero"),values=c("chartreuse4","white"))+
  theme(
          panel.grid.major = element_blank(),
          panel.grid.minor = element_blank(),
          axis.text.x = element_text(angle=45)
  ) +
  scale_x_discrete(labels=c("Gulf of Lion;Costa Calida-Algarve" = "Costa Calida-Algarve",
                            "Gulf of Lion;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Gulf of Lion;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Costa Calida;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Costa Calida;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Costa Calida;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Algarve;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Algarve;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Algarve;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Bay of Biscay;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Bay of Biscay;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Bay of Biscay;Costa Calida-Algarve" = "Costa Calida-Algarve"))+
  xlab("Pop1,Pop2")+
  ylab("f3")
p<-ggplotly(p,height=500)  %>% partial_bundle() 
p
```

### Unfiltered

```{r}
# Unfiltered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Ssard" & grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop_admix=as.character(vcf_f3_sp$pop_admix)
vcf_f3_sp$pop_1=as.character(vcf_f3_sp$pop_1)
vcf_f3_sp$pop_2=as.character(vcf_f3_sp$pop_2)

vcf_f3_sp[1:3,1]<-cell_spec(vcf_f3_sp[1:3,1], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[4:6,1]<-cell_spec(vcf_f3_sp[4:6,1], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[7:9,1]<-cell_spec(vcf_f3_sp[7:9,1], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[10:12,1]<-cell_spec(vcf_f3_sp[10:12,1], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3], color = color_med_atl$Col[4], bold = F)

kbl(vcf_f3_sp,col.names = c("Admixed population",
                           "Pop.1",
                           "Pop.2",
                           "f3",
                           "se",
                           "Z")
    ,escape = F,align=c(rep('c',times=6))) %>%
  kable_classic ("striped","hover", full_width = T,html_font = "Cambria") %>%
  row_spec(which(vcf_f3_sp$value<0 & vcf_f3_sp$Z<(-3)), bold = T, color = "black")
```

```{r}
# Unfiltered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Ssard" & grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop1_pop2=paste(vcf_f3_sp$pop_admix,";",vcf_f3_sp$pop_1,"-",vcf_f3_sp$pop_2,sep="")

vcf_f3_sp$pop1_pop2=factor(vcf_f3_sp$pop1_pop2,
                           levels=c(vcf_f3_sp$pop1_pop2))

def=c()
for (i in 1:nrow(vcf_f3_sp)){
  if (vcf_f3_sp$value[i]<0 & vcf_f3_sp$Z[i]<(-3)){
    def[i]="Negative"
  } else {
    def[i]="Zero"
  }
}
vcf_f3_sp$def=def


p<-ggplot(vcf_f3_sp,aes(x=pop1_pop2,y=value,fill=pop_admix))+
  geom_bar(stat="identity", aes(color=def))+
  geom_errorbar(aes(ymin=value-se, ymax=value+se),width=.2,
                 position=position_dodge(.9)) +
  theme_bw() + 
  scale_fill_manual(values=color_med_atl$Col)+
  scale_color_manual(breaks=c("Negative","Zero"),values=c("chartreuse4","white"))+
  theme(
          panel.grid.major = element_blank(),
          panel.grid.minor = element_blank(),
          axis.text.x = element_text(angle=45)
  ) +
  scale_x_discrete(labels=c("Gulf of Lion;Costa Calida-Algarve" = "Costa Calida-Algarve",
                            "Gulf of Lion;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Gulf of Lion;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Costa Calida;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Costa Calida;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Costa Calida;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Algarve;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Algarve;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Algarve;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Bay of Biscay;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Bay of Biscay;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Bay of Biscay;Costa Calida-Algarve" = "Costa Calida-Algarve"))+
  xlab("Pop1,Pop2")+
  ylab("f3")
p<-ggplotly(p,height=500)  %>% partial_bundle() 
p
```

Syngnathus typhle {data-navmenu="Species"}
=======================================================================

Row {.tabset data-height=50}
-----------------------
  
<center>

<font size="6">**Syngnathus typhle**</font>

</center>

Row {.tabset data-height=2500}
-----------------------

### Filtered

```{r}
# Filtered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Styph" & !grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop_admix=as.character(vcf_f3_sp$pop_admix)
vcf_f3_sp$pop_1=as.character(vcf_f3_sp$pop_1)
vcf_f3_sp$pop_2=as.character(vcf_f3_sp$pop_2)

vcf_f3_sp[1:3,1]<-cell_spec(vcf_f3_sp[1:3,1], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[4:6,1]<-cell_spec(vcf_f3_sp[4:6,1], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[7:9,1]<-cell_spec(vcf_f3_sp[7:9,1], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[10:12,1]<-cell_spec(vcf_f3_sp[10:12,1], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3], color = color_med_atl$Col[4], bold = F)

kbl(vcf_f3_sp,col.names = c("Admixed population",
                           "Pop.1",
                           "Pop.2",
                           "f3",
                           "se",
                           "Z")
    ,escape = F,align=c(rep('c',times=6))) %>%
  kable_classic ("striped","hover", full_width = T,html_font = "Cambria") %>%
  row_spec(which(vcf_f3_sp$value<0 & vcf_f3_sp$Z<(-3)), bold = T, color = "black")
```


```{r}
# Filtered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Styph" & !grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop1_pop2=paste(vcf_f3_sp$pop_admix,";",vcf_f3_sp$pop_1,"-",vcf_f3_sp$pop_2,sep="")

vcf_f3_sp$pop1_pop2=factor(vcf_f3_sp$pop1_pop2,
                           levels=c(vcf_f3_sp$pop1_pop2))

def=c()
for (i in 1:nrow(vcf_f3_sp)){
  if (vcf_f3_sp$value[i]<0 & vcf_f3_sp$Z[i]<(-3)){
    def[i]="Negative"
  } else {
    def[i]="Zero"
  }
}
vcf_f3_sp$def=def


p<-ggplot(vcf_f3_sp,aes(x=pop1_pop2,y=value,fill=pop_admix))+
  geom_bar(stat="identity", aes(color=def))+
  geom_errorbar(aes(ymin=value-se, ymax=value+se),width=.2,
                 position=position_dodge(.9)) +
  theme_bw() + 
  scale_fill_manual(values=color_med_atl$Col)+
  scale_color_manual(breaks=c("Negative","Zero"),values=c("chartreuse4","white"))+
  theme(
          panel.grid.major = element_blank(),
          panel.grid.minor = element_blank(),
          axis.text.x = element_text(angle=45)
  ) +
  scale_x_discrete(labels=c("Gulf of Lion;Costa Calida-Algarve" = "Costa Calida-Algarve",
                            "Gulf of Lion;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Gulf of Lion;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Costa Calida;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Costa Calida;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Costa Calida;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Algarve;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Algarve;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Algarve;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Bay of Biscay;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Bay of Biscay;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Bay of Biscay;Costa Calida-Algarve" = "Costa Calida-Algarve"))+
  xlab("Pop1,Pop2")+
  ylab("f3")
p<-ggplotly(p,height=500)  %>% partial_bundle() 
p
```

### Unfiltered

```{r}
# Unfiltered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Styph" & grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop_admix=as.character(vcf_f3_sp$pop_admix)
vcf_f3_sp$pop_1=as.character(vcf_f3_sp$pop_1)
vcf_f3_sp$pop_2=as.character(vcf_f3_sp$pop_2)

vcf_f3_sp[1:3,1]<-cell_spec(vcf_f3_sp[1:3,1], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[4:6,1]<-cell_spec(vcf_f3_sp[4:6,1], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[7:9,1]<-cell_spec(vcf_f3_sp[7:9,1], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[10:12,1]<-cell_spec(vcf_f3_sp[10:12,1], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Gulf of Lion"),2], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Costa Calida"),2], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Algarve"),2], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_1=="Bay of Biscay"),2], color = color_med_atl$Col[4], bold = F)

vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Gulf of Lion"),3], color = color_med_atl$Col[1], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Costa Calida"),3], color = color_med_atl$Col[2], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Algarve"),3], color = color_med_atl$Col[3], bold = F)
vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3]<-cell_spec(vcf_f3_sp[which(vcf_f3_sp$pop_2=="Bay of Biscay"),3], color = color_med_atl$Col[4], bold = F)

kbl(vcf_f3_sp,col.names = c("Admixed population",
                           "Pop.1",
                           "Pop.2",
                           "f3",
                           "se",
                           "Z")
    ,escape = F,align=c(rep('c',times=6))) %>%
  kable_classic ("striped","hover", full_width = T,html_font = "Cambria") %>%
  row_spec(which(vcf_f3_sp$value<0 & vcf_f3_sp$Z<(-3)), bold = T, color = "black")
```

```{r}
# Unfiltered
vcf_f3_sp=vcf_f3[vcf_f3$Species=="Styph" & grepl("UNFILTERED",vcf_f3$variable),]

vcf_f3_sp$pop_admix=substr(vcf_f3_sp$variable,4,5)
vcf_f3_sp$pop_1=substr(vcf_f3_sp$variable,7,8)
vcf_f3_sp$pop_2=substr(vcf_f3_sp$variable,10,11)

vcf_f3_sp=data.frame(pop_admix=vcf_f3_sp$pop_admix,
                     pop_1=vcf_f3_sp$pop_1,
                     pop_2=vcf_f3_sp$pop_2,
                     value=vcf_f3_sp$value,
                     se=vcf_f3_sp$se,
                     Z=vcf_f3_sp$z
                     )

vcf_f3_sp$pop_admix=factor(vcf_f3_sp$pop_admix,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_1=factor(vcf_f3_sp$pop_1,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$pop_2=factor(vcf_f3_sp$pop_2,levels=c("LI","MU","FA","GA")
                           ,labels=c("Gulf of Lion",
                                                        "Costa Calida",
                                                        "Algarve",
                                                        "Bay of Biscay"))

vcf_f3_sp$value=round(vcf_f3_sp$value,5)
vcf_f3_sp$se=round(vcf_f3_sp$se,5)
vcf_f3_sp$Z=round(vcf_f3_sp$Z,5)

vcf_f3_sp$pop1_pop2=paste(vcf_f3_sp$pop_admix,";",vcf_f3_sp$pop_1,"-",vcf_f3_sp$pop_2,sep="")

vcf_f3_sp$pop1_pop2=factor(vcf_f3_sp$pop1_pop2,
                           levels=c(vcf_f3_sp$pop1_pop2))

def=c()
for (i in 1:nrow(vcf_f3_sp)){
  if (vcf_f3_sp$value[i]<0 & vcf_f3_sp$Z[i]<(-3)){
    def[i]="Negative"
  } else {
    def[i]="Zero"
  }
}
vcf_f3_sp$def=def


p<-ggplot(vcf_f3_sp,aes(x=pop1_pop2,y=value,fill=pop_admix))+
  geom_bar(stat="identity", aes(color=def))+
  geom_errorbar(aes(ymin=value-se, ymax=value+se),width=.2,
                 position=position_dodge(.9)) +
  theme_bw() + 
  scale_fill_manual(values=color_med_atl$Col)+
  scale_color_manual(breaks=c("Negative","Zero"),values=c("chartreuse4","white"))+
  theme(
          panel.grid.major = element_blank(),
          panel.grid.minor = element_blank(),
          axis.text.x = element_text(angle=45)
  ) +
  scale_x_discrete(labels=c("Gulf of Lion;Costa Calida-Algarve" = "Costa Calida-Algarve",
                            "Gulf of Lion;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Gulf of Lion;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Costa Calida;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Costa Calida;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Costa Calida;Algarve-Bay of Biscay" = "Algarve-Bay of Biscay",
                            "Algarve;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Algarve;Gulf of Lion-Bay of Biscay" = "Gulf of Lion-Bay of Biscay",
                            "Algarve;Costa Calida-Bay of Biscay" = "Costa Calida-Bay of Biscay",
                            "Bay of Biscay;Gulf of Lion-Costa Calida" = "Gulf of Lion-Costa Calida",
                            "Bay of Biscay;Gulf of Lion-Algarve" = "Gulf of Lion-Algarve",
                            "Bay of Biscay;Costa Calida-Algarve" = "Costa Calida-Algarve"))+
  xlab("Pop1,Pop2")+
  ylab("f3")
p<-ggplotly(p,height=500)  %>% partial_bundle() 
p
```

Packages used {data-icon="fa-map"}
=======================================================================

```{r}
installed.packages()[names(sessionInfo()$otherPkgs), "Version"]
```